QuickTips Index - page 2
Copy RTF Text/Formatting From one TRichEdit to Another
Delphi's TRichEdit control is a text edit control that allows the user to enter text that includes variation in font attributes and paragraph formatting information. Here's how to copy the text from one RicheEdit to another, without loosing the RTF formatting.
Programmatically Get and Set the MediaPlayer Sound Volume
The TMediaPlayer Delphi component enables your application to control a media playing or recording device such as a CD-ROM player, video player/recorder. Find out how to get and set the sound volume while media is being played.
Programmatically Enable and Disable CD Auto-Run / Auto-Play
When a user inserts a CD into a CD drive, Windows AutoRun feature opens up an instance of Windows Explorer to display the content of the CD. There are many situations where AutoRun may need to be temporarily or persistently disabled. Here's how to programmatically enable or disable auto-play.
How to Re-Initialize an Object to its Default State
In Delphi OOP, the Create constructor is used to create an instance of a class. In most cases the constructor is uses to initialize property values. In the lifetime of an object, properties are assigned with non-default values. Here's the trick to re-initialize all the fields of a custom Delphi object.
How to Disable TEdit's Default PopUp (Context) Menu
When we right-click on an Edit component (or any other component that allows editing such as MaskEdit, Memo, DbEdit, etc.), by default the system's context menu pops up with options to undo, copy, paste, etc. Here's how to remove or disable the default context menu.
Programmatically Get and Set the State of the CapsLock and NumLock Keys
The VK_CAPITAL Windows virtual key constant defines the Caps Lock key.
The VK_NUMLOCK constant defines the Num Lock key. Here's how to programmatically get and set the state of those two keys.
How to Translate a Virtual Key Code to a Character
Windows defines special constants for each key the user can press. The virtual-key codes identify various virtual keys. In Delphi, the OnKeyDown and OnKeyUp events provide the lowest level of keyboard response. To use OnKeyDown or OnKeyUp to test for keys the user presses, you must use Virtual key codes to get the key pressed. Here's how to translate the virtual key code to the corresponding Windows character.
Add your Application to the Windows "Send To" Menu
Another approach to allowing the user to send a file to your Delphi application for processing, without the need to register a file type, is to add your application to the special Windows "Send To" menu. Here's how to programmatically add your application to the "Send To" menu.
Drawing a Focus Rectangle Around the Active Control
By using the OnActiveControlChange event of the Delphi's TScreen class you can change the background color of the active input control. To create event more eye-catching effect you could "draw" a rectange around the focused control.
How to Detach an Event Handler from a Control Event
Almost all the code you write in your Delphi applications is executed, directly or indirectly, in response to events. For example, when a user clicks a button, an OnClick event is being raised. You can write an event handling procedure to react on this event. Here's how to detach (remove, disable) the event handling code from the event...
How to Draw a Gradient Fill on a Canvas
Here are two custom Delphi functions to paint a Canvas object using gradient fill from one color value to another, either vertical or horizontal.
How to Animate (Scroll) Application Title on the TaskBar
If a lengthy process is about to start in you Delphi application, you can indicate that the process is still running by, for example, animating the title of your application, i.e. animating the caption of your application's TaskBar button. Here's how to grab a user attention...
Create a Resizable Form with No Border (FormStyle = bsNone)
There may be situations when you want to remove a form's border (and title bar) *but* still leave the option for a user to resize the form. Here's a handy trick to enable form resizing when BorderStyle is set to bsNone for Delphi forms.
How to Display "Bold" Items in the TTreeView component
By default (Windows drawing), all items (tree nodes) of a tree view share the same font styling. If you only want to apply *bold* to some tree items (their Captions), you can use a "special" TreeView API. Here's how to *bold* items in Delphi applications.
TListBox with Radio Buttons
Delphi's TListBox VCL component displays a collection of items in a scrollable list. The MultiSelect property determines if a user can select more than one item. Here's how to draw a radio button for each of the items in a List Box...
How to Access a TRadioButton from a TRadioGroup - Disable, Change Font, etc.
Here's how to access a specific radio button either by Index or by Caption. When you "grab" the TRadioButton you can disable it, change its color, etc...
How to Jump to the Last Item in the TListBox
When dynamically adding items to the ListBox you might want to ensure that the last added item is visible. Here's how to use the TopIndex property to ensure the visibility of the last item (and all the items at the end of the list that can "fit" into the box).
How to Programmatically Open the Recycle Bin
When you delete a file in Windows Explorer, the file appears in the Recycle Bin. The file remains in the Recycle Bin until you empty the Recycle Bin or restore the file. Here's how to programmatically display the Recycle Bin to a user of your Delphi application.
Activate a Running Instance when a User Opens an Associated File (By Extension)
When a user select more than one file to be opened by your Delphi application (after you have registered your own file type - extension), Windows will start as many new instances of your application as there are files being opened. Here's how to make sure that all the processed files are being handled by only one instance of the application.
How to Run your Application by Double-Clicking on a File (Register Extension)
When creating applications, it is often necessary to store (application related) data on the file system. You may choose to create your own file type (with a *unique* extension) and then associate that extension with your application through Windows. This tells Windows to automatically run your application when a user double-clicks a file in Windows Explorer, for example.
How to Use a Function or a Procedure as a Parameter in another Function
Here's how to send a function (or a procedure) as a parameter to another function in Delphi.
How to Move ListBox Items with the Mouse (Drag and Drop)
Here's how to allow a user to rearrange the items (change position) of a list box using drag and drop...
How to Detect a TPopupMenu's OnClose (OnPopDown) Event
Unfortunately, the TPopupMenu does not expose an event you can handle that will fire when the menu gets closed - either after a user has selected an item from the menu or has activated some other UI element. Here's a fix to this behavior.
How to Remove the "Today" Mark from the TDateTimePicker
The TDateTimePicker component displays a list box for entering dates or times. By design it displays the label "today" at the bottom of the control allowing a user to quickly select the today's date. Here's how to remove the "today" marker from the TDateTimePicker.
How to Clone a Delphi Form
Besides instantiating Delphi Forms dynamically, you can decide to create a *clone* of an existing form - by using the TMemoryStream's ReadComponent and WriteComponent methods.
