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

QuickTips Index

Implementing the OnBeforeCreate and OnAfterCreate Events for Delphi Forms
The TForm's OnCreate event is called when the form is created. Usually, you would write an OnCreate event handler to perform special processing when the form is created - such as setting any startup information (initial control property values, for example) for form operation. If you are using VFI you might need to have code that executes after all OnCreate event handler has been called for all inherited forms. Here's how.

MDI Child Count By Class
An MDI application typically displays more than one document or child window within a single parent window. A question: I have two types of MDI Child forms in my application. How might I go about counting each one? One is TFrmStatus the Other is FrmChannel. How do I know how many TFrmStatus children are alive? Here's the answer.

Check if an XML Conforms to the Rules of a DTD
A DTD file can be created to specify valid tags and attributes. The purpose of a DTD is to define the structure of an XML document. It defines the structure with a list of legal elements. Here's how to programmatically validate an XML against a DTD using TXMLDocument and Delphi.

Challenge: Un-Camel-Case a String
Camel casing is a convention for capitalizing identifiers where the first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. Examples inculde: MySuperWebSite, DelphiSoureCode, FirstYearSalary, etc. Your challenge is to code a custom Delphi function: UnCamelCase. The function should return a string that has been "de-camel-cased" - where "words" are separated by a space character.

Allow Only One Application Execution Per Windows Session
Here's how to allow only one execution of your Delphi application per Windows session. A warning message appears if a user tries to execute more than once without restarting Windows.

Avoid New MDI Child Resizing Animation (and Delay) in Delphi MDI Applications
If you are creating MDI applications using Delphi, you must have noticed some "quirks" or issues that you cannot simply handle / fix from your code. When creating (to show) an MDI child an animation of resizing will take place. This animation might look ugly if the code executed during the creation of your MDI child takes some time to process. Here's how to prevent window updating when creating new MDI child forms.

Passing a Simple Type Variable (Integer) for a Pointer Parameter.
On procedureal pointers and callback functions. On value parameters in function calls. On pointers and simple types. On everything.

Challenge: Get Palindromic Numbers
Your challenge is to create the fastest Delphi algorithm to find all palindromic numbers from 1 to 10. Palindromic numbers are the same when written forwards or backwards, like: 123321.

Challenge: Fastest Unique Random Number Generator
Your challenge is to create the fastest algorithm to fill in an array with unique integer numbers.

TVatCalculator - Value Added Tax Calculator Implementation in Delphi
VAT or Value Added Tax is a common form of taxation in the European Union (EU). VAT is added on top of the cost of a product or service and generates revenue for a government. If you are working on an accounting-type application, you will have to deal with VAT, Gross and Net values all the time. The TVATCalculator class provides functions to help you calculate gross from net for a given vat value, net from gross, net for vat, ...

Programmatically Retrieve Your IP Address Behind a Router / Proxy / Gateway
An IP Address (Internet Protocol Address) identifies and allows computers (printers, routers) to communicate with each other on a computer network. If you need to know the WAN-IP of your router using Delphi code, you can take advantage of the "http://www.whatismyip.com" service which can reveal the IP address of machine. Here's how.

Delayed Event Handling Using Event Handler Detaching
When you have an event handler which takes some time (> 0.1 sec) to run, but you don't want another click or a double click to call the event handler a second time before the first call has finished, you can detach the event handler from the event while the event handling code is being executed.

Changing the Title of a Print Dialog in Delphi
The TPrintDialog component displays a standard Windows dialog box for sending jobs to a printer. Unfortunately, the TPrintDialog does not expose the Title property. By handing the OnShow event of a print dialog you can specify the text for the dialog’s title bar:

Freeing Objects in Delphi's TStrings Items
Delphi TStrings object does not own the objects you add this way. Objects added to the TStrings object still exist even if the TStrings instance is destroyed. Objects must be explicitly destroyed by the application / developer - you; or your application will leak memory. Here's a generic solution to freeing the memory used by objects stored along strings in a TStrings descendant.

Programmatically Disconnect a Mapped Network Drive
When working with files and folders in your Delphi applications you might need to provide a user with an option to map a shared network path to a drive letter AND to un-map or disconnect a mapped network location. This time, we want to remove a network connection from Delphi code...

Programmatically Execute the Map Network Drive Dialog
When working with files and folder in your Delphi applications you might need to provide a user with an option to map a network path to a drive letter. If you want to programmatically call the Map Network Drive Dialog in your Delphi application, you need to call the WNetConnectionDialog1 Window API function.

Convert an Amount of Microseconds into a TDateTime Value
When testing your code for speed, or when you have some lengthy function, and you need to display how much time some process took to execute, you would maybe need to take microseconds into account also. Here's a custom MicrosecondsToTime function you can use to convert an amount of microseconds into a TDateTime value and then convert to a more user friendly representation using the FormatDateTime function.

Print Documents From Delphi - Print PDF, DOC, XLS, HTML, RTF, DOCX, TXT
If your Delphi application needs to operate on various types of files, one of the tasks you might have for your application is to allow the user of the application to print a file, whatever the file type is. Here's how to use ShellExecute API call to print any printable document to the default of user selected printer, programmatically from Delphi.

Challenge: Create a Custom Delphi Function: RemoveEmptyFolders
Your task is to code a custom Delphi function RemoveEmptyFolders. RemoveEmptyFolders takes 1 path names (directory) and should remove / delete all empty sub-folder at any (sub) level.

Get Selected Tabs of a Multiselect TTabControl
Delphi's TTabControl (Win32 palette) can be used to add a control with multiple tab settings to a form. The Multiselect property of the TTabControl specifies whether multiple tabs can be selected at the same time. Here's how to get the list of indexes or strings one can use to determine what tabs are selected when multiselect for TtabControl is set to true.

Delphi Exercise: Create a Custom Delphi Function: ExtractBasePath
Your task is to code a custom Delphi function ExtractBasePath. ExtractBasePath takes 2 path names (directory or file) and should return the base / common path for the paths provided.

Create Manifest for Vista UAC if Not Running Under Administrative Rights
By programmatically editing the Windows Registry, using the TRegistry object, you can you can "automagically" start your Delphi programs whenever Windows launches. On Vindows Vista, UAC will stop you from altering the Registry if a user runing the application does not have administrative rights. Learn how to create an application manifest file to request admin execution level. Automate the process of creating manifest files using a simple (source included) Delphi application.

How to Check if a Given File Name is Valid Using Delphi
If you have an application that operates on the file system and one of the tasks of the application is creating or manipulating files you might need to check if a given file name is valid - will Windows allow your code to save a file using the specified file name. A custom Delphi function IsFileNameValid does the validation.

Is Computer Joined to a Domain - Programmatically Check using Delphi
If you need to programmatically check if a machine running your application is a part of a domain you can exploit functions found in the netapi32.dll. The trick is in using the NetRenameMachineInDomain function which can be used to change the name of a computer in a domain.

Convert a Drive Letter ("C") to a Drive Number (3)
I have an application that needs to "export" a set of files into a specified folder on a drive. Files can come from various sources: hard disk, usb disk, network drive, etc. DiskFree returns the number of free bytes on the specified drive but takes a drive number as a parameter. How to convert a drive letter to a drive numer...

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

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

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

All rights reserved.