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

About Delphi Programming Tips - 2008

Delphi tips from the free About Delphi Programming newsletter.
More tips by year: 2008 | 2007 | 2006 | 2005 | 2004 | 2003 | 2002 | 2001 | 2000 | 1999
Prevent the System from Entering Sleep or Turning off the Display
If you have a critical application running and you want to prevent the system from entering sleep or turning off the display while the application is running you need to call a Windows API function named SetThreadExecutionState. The TSystemCritical is a wrapper of this api call. Full source code included.
Is your Delphi Application Running under Terminal Services as a Remote Session?
Windows Terminal Services environment enables users to access Windows-based programs that are installed on a terminal server, or to access the full Windows desktop. Users can connect to a terminal server to run programs, save files, and use network resources on that server. Here's a handy Delphi function using the GetSystemMetrics API call to test if the application is remotely controlled.
Need to Return a TStrignList (any object) from a Delphi Function?
Do you know that a Delphi function can return any object type value, like a string list (TStringList) or a button (TButton)? If you know then I guess you also know that you have to be very careful when calling such a function. When a function returns an instance of an object - always make sure you free the object when no longer needed.
Non Focusable Window - Create a Delphi Form that can Not be Activated
When Delphi creates a form, the Create method calls the CreteWindowEx API function to crete the actual window. CreateParams methods called before the window is actually created lets you change the default style of a window when it is created to suit your particular needs. Here's how to create a form that cannot be activated - will never have the focus - will never be a foreground window.
Where to Find Glyphs and Icons for a Delphi Application, Menu, Toolbar
A glyph in Delphi lingo is a bitmap image that can be displayed on a BitBtn or SpeedButton controls using the controls Glyph property. Glyphs and icons (and graphics in general) make your application user interface elements look professional and unique.
Where to Locate the Missing TServerSocket and TClientSocket Delphi components
If you have installed a newer Delphi version and you have a legacy application using the TServerSocket and TClientSocket component - you would face a problem! Delphi socket components are no longer installed into the component palette by design - therefore you will not be able to compile your project. Here's where to find and how to install the two sockets component.
Set TRichEdit Print Margins Programatically
Rich Edit provides a simple [b]Print method[/b] allowing you to programmatically print the (formatted) contents of the rich edit to the active printer - with a single line of code. Unfortunatelly, there's no exposed functionality to set printer margins as you are accustomed to in various word processing applications.
Hide a Delphi 2007 Application Button from the TaskBar (with MainFormOnTaskBar)
With Delphi 2007, a new property of the Application object, the MainFormOnTaskbar property controls how Windows taskbar buttons are handled by VCL. The code using SetWindowLong to change the application's window style parameters no longer works. Here's how to hide the Delphi 2007 application taskbar button.
Calculating the Zodiac Sign from the Birth Date
The ZodiacSign, custom Delphi function, will return the name of the zodiac sign for a given date value.
Left Align Caption of a TSpeedButton Delphi button
When you have a group of Delphi's speed buttons one after another in vertical "line", with Layout set to blGlyphLeft the buttons do not look so nice. What you might start looking for is the "Caption Layout" property to let you set the alignement of the button caption. Sadly, you'll find no such property :( Or, would you?
Handling Global Application Object Events in Delphi
The TapplicationEvents Delphi component wraps the global Application object available to you in all Delphi applications. When you add a TApplicationEvents object to a (main) form, the unique Application object forwards all events to the TApplicationEvents object. For some events the Application object exposes, the TApplicationEvents does not expose the event in the Object Inspector. Here's what to do.
Dim Out the Main Form of an Application When Modal Form is Displayed
To emphasise the importance of a modal form and the information it presents, you could gray out the main form of your Delphi application when the modal form is activated. Use the OnModalBegin and OnModalEnd events of the TApplicationEvents component along with AlphaBlend transparency effect.
How to Refresh a DBGrid without Loosing the Current Row Position
When DBGrid is used to display data from a dataset (query or table), by design, after you call Refresh method on a dataset (re-open) (for example, using a DBNavigator), the current row position will be reseted to zero (ok, first). This means that if a user has selected a row somewhere near the bottom of a DBGrid, after a Refresh, the active row will be changed to first :( Here's one answer to this problem...
Select Which Panel Displays AutoHint in Delphi's TStatusBar
When StatusBar's AutoHint is true, the status bar automatically responds to hint actions by displaying the long version of the hint’s text in the first panel. You might want the hint to be displayed in the second or third panel .. here's how.
Take a Screen Shot of an Inactive Window - Using PrintWindow API and Delphi
In most cases you will want to take a screen shot of the active window or the Windows Desktop. What if you need to do a screen capture of all the running applications - most of them will be inactive and not visible to the user? Here's how to use the PrintWindow API from Delphi.
Use Custom CheckBox Images for a ListView
When the ViewStyle property of a TListBox Delphi control is set to vsReport and CheckBoxes is set to true, list view includes a check box next to the items in the list. By design this check box is, well, "ugly". It has a nasty thick 2 pisel border - and there's no property to change it. One way to have nice check boxes in a list virw control is to use your own custom graphics (16x16 px bitmap image) and draw it over the original check box. Hre's how...
No Main Form Delphi Application
Every Delphi applications must have a main form. The main form is the first form created in the body of the application. When the main form closes, the application terminates. What if you need to create an application where every form is equally important (for example like IE) - where closing the main form will *not* close the application.
Formatting Lines in Rich Edit using Delphi's SelText and SelStart
While you can create nice user interface "around" the rich edit control with toolbar buttons to set and change text display attributes, adding formatted lines to rich edit programmaticaly is fairly cumbersome - as you will see.
Custom Drawing of TListView Items - Font, Colors, Graphics
If you want to apply custom drawing (fonts, color, graphics) for each individual list item you can simply handle an event or two - and have a list view full of color and visually more attractive elements. The OnAdvancedCustomDrawItem event can be used to customize the drawing of individual items on the list view's canvas. Here's a quick Delphi example.
Opening Office Documents (Word, Excel) in TWebBrowser on Vista and Office 2007
When, in your Delphi application, you are using the TWebBrowser control to open Word (Excel) document for preview and/or print- if your application is running on Vista with Office 2007 installed you might experience weird behaviors. Documents open in a new Word instance rather than in the web browser window. Here's a quick fix.
TreeView Items - Dynamic Context (Popup) Menus
In complex tree views, you might want to display customized - dynamic context (popup) menu for each tree node. Here's how to handle the OnContextPopup event to display tree view node aware context menu.
Impementing UnQuickSort in Delphi - How to Use the TListSortCompare function
Understanding and Using Delphi's TListSortCompare - a function used as a parameter for the Sort method of the TList class. Learn how to randomize TList items - by soting in random order!
What is "var Form1:TForm1" in Delphi Form's Unit Interface section?
When you add a new form to a Delphi project, a form and its associated unit is included in the application. There's a global variable "Form1" in the interface section - what is it used for?

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 2008 Tips

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

All rights reserved.