1. Home
  2. Computing & Technology
  3. Delphi Programming

About Delphi Programming Tips - 2007

Delphi tips from the free About Delphi Programming newsletter.
More tips by year: 2008 | 2007 | 2006 | 2005 | 2004 | 2003 | 2002 | 2001 | 2000 | 1999
How Much Memory Is Your Delphi Program Occupying?
No matter how much you try to code without bugs and memory leaks .. the more complex the application the more possible is to leak some memory.
Date Time SQL Queries: Formating Date Time Values for Access SQL in Delphi
Fixing the "Parameter object is improperly defined. Inconsistent or incomplete information was provided" error when formatting date time values for SQL queries when using Access and Delphi.
Force TListView's Edit Mode using a Keyboard Shortcut
If you want to allow the user to start editing the caption of a list view item by a keyboard "shortcut", rather than by the mouse action, you need to handle the OnKeyDown event and call the BeginEdit method. Here's how using Delphi.
Displaying Enumerated Properties in a Selectable List
Enumerated Delphi properties appear as selectable items in a drop down list at design-time in Delphi's Object Inspector. Here's how to provide a run-time selection of enum values for your application users.
Disable CTRL+V Shortcut Key for a TCustomEdit
Sometimes you need to disallow a user from using keyboard shortcuts for common clipboard operations such as copy (CTRL+C) or paste (CTRL+V) while an edit control has the input focus. Here's how when using Delphi.
Restore a Delphi Form from Minimized state to the Previous State
One problem with the WindowState Delphi property is that if a form is minimized and you need to restore it to the previous size and location - you do not know if the form was previously maximized or was displayed in its "normal" (neither minimized nor maximized) state! Here's what to do ...
Preview HTTP Posted Data using Delphi and TWebBrowser
Before actually sending information you might need to preview the data to be posted. Use the OnBeforeNavigate2 event of the TWebBrowser Delphi control.
Programmatically Executing HTTP POST
How to programmatically upload multiple files to an HTML form using the HTTP Post method - from Delphi.
Implementing OnActivate / OnDeactivate for MDI Child Forms
What if you need to extract some data from the MDI child form being deactivated from the form being activated? You need to handle a special MDI Windows message: WM_MDIACTIVATE. Here's how to do it in Delphi.
Iterating Over a Set type Variable in Delphi
Delphi's set type is one of the features of the language commonly not found in other programming languages. Sets represent a collection of values of the same ordinal type. Using the new 'for .. in' loop you can easily iterate through every possible element in a set. Here's how.
Focus the First Entry Control in a Container
In any decent complex form design you will probably have edit controls (edit boxes, drop down lists, radio buttons, check boxes, etc) contained within a parent container control (TPanel, TGroupBox, ...). Here's how to set the input focus to the first control that can receive the focus in Delphi applications.
Implementing "Contains Focus" for Delphi's Container Controls: TPanel, TGroupBox
In complex form designs where you have dozens of controls contained in several containers it is sometimes necessary to find out whether the focused control (the one with the input focus) is a child of some overall parent of a group of controls. Here's how to check if a specific (container type) control contains the input focus.
Get Directory Creation, Modified, Last Accessed and Last Write Date and Time
While Delphi provides many (file and) directory related functions and procedures to help you operate on folders and file, quite a few tasks equire you to dive into the world of Windows API calls. Here's an example function that will display all the important time values for a given directory: creation time, date and time the specified directory was last accessed and date and time the specified file or directory was last written to.
Get Parent Folder / Directory
Delphi's RTL library exposes dozens of file name related functions and procedures. You might be surprised that one function is "missing": how to get the parent folder (directory) for a specified file / folder name. Here's how!
Get Windows Running Time
If you need to display how many days (minutes, seconds) have passed since Windows have been started, you need to convert miliseconds to days, hours, minutes. Here's how in Delphi.
Is the Current Windows user a Computer Administrator?
In Windows there are two main types of user acount types: "Computer Administrator" and "Limited". If you need to check, from your Delphi application, if the currently logged user is an administrator or a member of the Administrators group, use the "IsWindowsAdmin" function...
Array as a Function Return Type and Method Parameter
When you declare Delphi routines that take array parameters, you cannot include index type specifiers in the parameter declarations. The same goes for functions that return array values. Here's how to solve this "problem".
Drop Multiple Instances of a Component on a Delphi Form
In complex Delphi application user interface designs, where you need to place several instances of the same component on a form, you might want to speed the process of adding component. Here's how.
Select a Control Parent in the Delphi Form Designer
When designing forms (frames) for your Delphi application, you often use container type controls such as a TPanel or TGroupBox to hold other controls. In complex form designs, where containers are used inside other containers, it is sometimes hard to quickly "navigate" to a particular button, for example, to change its Caption. Use the ESC key to quickly select a control's parent.
Remove MDI Child Title Bar
For an MDI Delphi child form, setting the BorderStyle property to bsNone does NOT remove the title bar. The only way to remove (hide) the border of an MDI child form is by messing with the CreateParams procedure. Here's how...
Adding Custom Properties to Delphi Forms; Overriding the Create Constructor
If you need to add a custom property to a form and have it initialized *before* the OnCreate event, you will need to override the form's constructor. Here's how to override Delphi form's constructor.
Disable Automatic Hint Feature for the TTreeView
By Windows design, when you hover your mouse over an item in a tree view, a hint (tooltip) window appears containing the title of the item under the mouse cursor, if the entire title is not currently visible. Sometimes, you might want to disable such tree view behavior in order to show, for example, custom hints for every tree node. Here's how...
How to Debug Delphi VCL Source Code (Set a Breakpoint in the VCL)
No matter how careful you are when writing code, your programs are likely to contain errors, or bugs, that prevent them from running the way you intended. Here's how to step into the VCL (and RTL) source code ...
Parsing Command Line Parameters with Delphi
Delphi's ParamStr and ParamCount functions are designed to help operate the parameters (command-line arguments) passed to the application. Due to the way ParamStr function is implemented in Delphi, parameters passed using double quotes ("") will not be parsed correctly (quotes will be removed). The "CmdLineHelper" unit provides 3 custom Delphi functions to overcome the problem of the RTL's ParamStr implementation.
How to Display the & (ampersand) Character on Labels and Buttons
By placing two ampesands together - you state that the character following the first one is *not* used as the accelerator - rather you actually want to get it (only one) displayed. Find more about the "&" character in Delphi.
Understanding Delphi's NIL value and the Assigned RTL Function
In Delphi, the NIL constant (also a reserved word) is a pointer value defined as "not-assigned" or "pointer to nothing" or "undetermined". Understand NIL before you use it...
Set CheckBox.Checked without the OnClick event
The TCheckBox Delphi control displays a check box that can be on (checked) or off (unchecked). The Checked property specifies whether the check box is checked or not. When the user click the check box to change its Checked state, the OnClick event for the check box is fired. Here's how to disable the OnClick event when you programmatically change the Checked property.
Convert RGB Color to CYMK
The CMYK (Cyan, Magenta, Yellow, Black - Key Plate) model, refers to the 4 ink colors used by the printing press. The RGB (Red, Green, Blue) is used primarily in web design. Here's how to programmatically convert a RGB color value to a CMYK value.
An Invalid Hard-Cast is NIL in Delphi for .NET
Since .NET is more strict when it comes to casting an object to a different type, Delphi for .NET does not allow "unsafe" hard-casts. An invalid hard-cast in Delphi for .NET return NIL. Find out what it means.
TObject(Sender) vs. (Sender as TObject)
Learn about the diffrences between a hard-cast and a safe AS cast and how to create the safe hard-cast using the is-check.
Delete Multiple Selected Items in a TListBox Delphi Control
The TListBox Delphi control displays collection of strings in a scrollable list. By setting the MultiSelect property to true, the user can select more than one item at a time. Here's the code to delete multiple selected items in the list box Delphi control.
Implement On Item Checked Event for the TListView
The TListView Delphi control displays a list of items in a fashion similar to how Windows Explorer displays files and folders. Unfortunately, the TListView does not raise an event when the "Checked" state changes for a TListItem (when ViewStyle is vsReport and Checkboxes is set to true). Here's how to Implement the On Item Checked Event for the TListView.
How to Parse TAB Delimited Files in Delphi
TAB delimited text files contain lines of code with each chunk (column) of data (string) separated by the TAB character. Most database and spreadsheet programs are able to read or save data in a delimited format. Here's how to parse TAB delimited files in Delphi.
IsDirectoryEmpty
Delphi does not provide any "ready made" RTL function to test if a given directory (folder) is empty, i.e. contains no files or sub-folders. The IsDirectoryEmpty function provides the answer.
How to Override Delphi Form's Restore Operation?
The WM_SYSCOMAND can be used to trap the restore window operation. When the form is maximized the "Maximize" button changes its look and operation. Clicking the restore button restores the window to its previous (normal, before it was maximized) position and size. By overriding (changing) the default "restore" action, you can for example, create a Delphi form that can be only mimimized or maximized.
How to Declare a Constant Record in Delphi
Record data types in Delphi represent a mixed set of elements. Each element is called a field; the declaration of a record type specifies a name and type for each field. Here's how to Do create a constant or "read-only" record...
How to Store a String value to a Tag Property of a Delphi control
Every Delphi component exposes the Tag property which can be used to store an integer value as part of a component. You might want to store a string value in the tag property of a control (TEdit, TButton, etc.) to let every control cary an additional string value. Here's how..
How to Hide the Tabs of the TPageControl Delphi control
If you need to create a wizard-like user interface where you have "Next" and "Previous" buttons "moving" a user forward and backward through a set of pages (dialogs), you might want to hide the tabs of the PageControl and thus disable selecting a particular page by the mouse.
Programmatically Detect the MyDocuments Folder for the Current Windows User
If your Delphi program creates application specific documents you want to be stored in the "MyDocuments" folder for the currently logged Windows user, you need to programmatically determine the path to the "MyDocuments" folder. Here's how using Delphi...
Save (and Load) all the Images from a TImageList to a Single File
If you want to reuse images from a the TImageList control, you can populate the TImageList with images, store all the images in a single resource-like file, then reuse at run time, by dynamically restoring the TImageList control from the saved file. Here's how...
PopupMenu With Different Item Heights (and Custom Graphics)
If you need to have different height for some of the menu items, in Delphi applications, you must turn to owner drawing. Here's how to draw a custom szed image for a popup menu item.
How to Hide / Show the Main Menu of a Delphi Application
The TMainMenu Delphi component does not expose the Visible property to let you show or hide the menu for a form programmatically, does it? It does not, but there is a way to hide the main menu for a Delphi form at run time. Here's how...
How to Implement the OnCreate event for a Delphi TFrame object
A frame, like a form, is a container for other components. Frames can be nested within forms or other frames, and they can be saved on the Component palette for easy reuse. Once you start using frames, you'll note there's no OnCreate event you can use to initialize your frames. Here's how to mimic the OnCreate event for Delphi frames.
Apply Custom Transparent Color for the TImage Delphi Control
The Transparent property of the TImage Delphi control specifies whether the objects behind the image should show through the background of the image. If you do not want the color of the bottom-left pixel to specify which image color should be "transparent" - you can set theTransparentColor property programmatically.
Display Custom Hints for TListView Sub Items
You use the TListView Delphi control to display a list of items in a fashion similar to how Windows Explorer displays files and folders. Here's how to display custom hints for each list view sub item.
Create Collapsible Code Blocks in Delphi Code Editor
In Delphi (both Win32 and .Net) you can apply a special {$REGION 'Region Name'} directive to mark a "named" collapsible regions in the code editor.
Display an Icon on TBitBtn Delphi control with the help of TImageList
The TBitBtn Delphi control is a button control that can include a bitmap on its face. By design, the Glyph property can only display BMP (Windows Bitmap) images. If you need to display an icon (ICO) file on a BitBtn, you can use the GetBitmap method of a TImageList. Here's how.
Understanding ScreenToClient and ClientToScreen Delphi methods
Every Delphi control, descendant of the TControl class, exposes two methods you can use to convert point coordinates: ScreenToClient and ClientToScreen. Here's when and how to use them.

Explore Delphi Programming

More from About.com

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2007 Tips

©2008 About.com, a part of The New York Times Company.

All rights reserved.