Chapter 28 Key Takeaways
-
The LCL provides a rich set of common controls — TLabel, TEdit, TMemo, TButton, TComboBox, TCheckBox, TRadioButton, TListBox, TRadioGroup — each designed for a specific interaction pattern. Choose the right control for the right task.
-
Layout is built with three tools:
Alignfor major structural regions (top toolbar, left sidebar, client area),Anchorsfor flexible positioning within regions, andBorderSpacingfor margins and gaps. Avoid hardcoded pixel positions. -
TStringGrid is a versatile tabular display with fixed header rows, editable cells, row highlighting, and column resizing. For custom cell rendering, use the
OnDrawCellevent. -
Data entry forms require careful attention to tab order, validation strategy (on-submit, on-exit, or as-you-type), and focus management. Always call
SetFocusandSelectAllwhen highlighting a validation error. -
Modal forms block the parent window and return a ModalResult. Modeless forms coexist with the parent. Use modal for dialogs that require a decision; use modeless for auxiliary windows.
-
Pass data between forms via public properties or methods — not global variables. A form is just an object; treat it like one.
-
Shared event handlers with
SenderandTageliminate code duplication. Ten buttons can share one handler. -
Controls can be created at runtime using
TControl.Create(Owner)and setting theParentproperty. This enables data-driven UIs where the number of controls depends on the data. -
Custom events using method pointers (
procedure(Sender: TObject) of object) let your business logic classes notify the UI without depending on it — the Observer pattern in action. -
Forms are classes. Everything you learned about OOP in Part III — encapsulation, properties, methods, inheritance — applies directly to form design.