Control Building
Many of RegistryRobot's tweaks require user input. RegistryRobot
provides spin controls for numeric values, edit boxes for text values, memo boxes for multiline text, check boxes for on/off toggles, and buttons that can browse for files, icons, or folders. The exact type of special user input is determined by a field named
Special in the file Data.xml. A given tweak may encompass several data records, and each of them may require creation of one or more controls.

Creating controls at runtime is a little different from the
typical visual-design process. The initial call to the
Create constructor establishes the form as the owner of the control, but that won't make the control appear. You must also set the control's
Parent property to the form itself or to a container component. RegistryRobot uses a
TScrollBox component named
sbCtrls as the parent for all of the tweak-specific controls. If there's not enough room, the
TScrollBox automatically displays horizontal or vertical scrollbars.

When you create controls in the form designer, they're given
unique names automatically. If you create them at run time, you're responsible for ensuring the names are unique. RegistryRobot simply appends 0 (zero) to the names of the first row of controls, 1 (one) to the next row, and so on. Naturally, you have to set the
Left and Top properties so all of the controls don't wind up on top of each other. Depending on the control, you'll set other properties such as
Width,
Text,
Caption, and so on. Finally, you may need to set one or more event-handler properties. For example, when RegistryRobot creates a button to browse for an icon, it sets the button's
OnClick event handler to the
btnIconClick method. All of the routines that add controls are found within the function
DoSpecial, which in turn is contained in the main form's
tv1Change method, in the file Mainu.pas.

Initially, I separated controls on the same line by 8 pixels,
and started each line 32 pixels below the line before. The result was truly ugly. Most lines were too far apart vertically, and the controls within them were too close together. Controls that should have lined up vertically were all over the map. When you're designing a form visually, this sort of problem just doesn't come up, because you can see the results immediately.

To minimize problems with uneven placement, I added code to
round calculated positions upward to the nearest 8 pixels. This helped a bit, but a control like a text box that was preceded by an identifying label still didn't line up properly. I hit on the solution of setting the label's
Caption property to an empty string, setting its
Alignment
property to taRightJustify,
and placing the label at the correct location for the end of the text. When I then set the
Caption to the desired value, the label extended to the left. Any edit boxes or other controls after such labels would all line up perfectly with those above or below
them.

The vertical increment of 32 pixels between lines of controls
was necessary for lines that contained buttons, but was too much for lines of edit boxes or check boxes, and too little for lines containing a multiline memo box. The solution was simple enough. For each line of controls, I had RegistryRobot keep track of the greatest height. To find the start of the next line, I had the program add that height plus an additional 8 pixels.

As you can see, building an attractive group of controls in code
can be difficult. The effort certainly makes one appreciate Delphi's visual form-designer.

Top Downloads

Automatic Renewal Program: Your subscription will continue without interruption for as long as you wish, unless
you instruct us otherwise. Your subscription will automatically renew at the end of the term unless you authorize
cancellation. Each year, you'll receive a notice and you authorize that your credit/debit card will be charged the
annual subscription rate(s). You may cancel at any time during your subscription and receive a full refund on all
unsent issues. If your credit/debit card or other billing method can not be charged, we will bill you directly instead. Contact Customer Service