VCL Fundamentals
33.1 The VCL Architecture
VCL = Windows-only, a native Win32/Win64 wrapper. It's fast, mature, and has a huge third-party ecosystem.
TObject
└── TPersistent (streaming, Assign)
└── TComponent (Owner, Name, Tag, published properties, design-time support)
├── TControl (visual: Left, Top, Width, Height, Align, Anchors, Visible, Enabled)
│ ├── TGraphicControl (no window handle: TLabel, TShape, TImage, TSpeedButton)
│ └── TWinControl (has an HWND: focus, children)
│ └── TCustomControl → TButton, TEdit, TMemo, TPanel, TListView, TForm...
└── Non-visual components (TTimer, TDataSource, TFDConnection, TActionList, TOpenDialog)33.2 Forms and Common Controls
TButton, TLabel, TEdit, TMemo, TCheckBox, TRadioButton, TListBox, TComboBox, TPanel, TGroupBox, TRadioGroup, TScrollBar, TMainMenu, TPopupMenu, TActionList
TBitBtn, TSpeedButton, TMaskEdit, TStringGrid, TDrawGrid, TImage, TShape, TScrollBox, TSplitter, TLabeledEdit, TColorBox, TValueListEditor, TControlBar
TPageControl, TTabControl, TTreeView, TListView, TRichEdit, TProgressBar, TTrackBar, TUpDown, TDateTimePicker, TMonthCalendar, TStatusBar, TToolBar, THeaderControl, TImageList TTimer, TPaintBox, TMediaPlayer
TOpenDialog, TSaveDialog, TFontDialog, TColorDialog, TPrintDialog, TFindDialog, TTaskDialog, TFileOpenDialog
TDBGrid, TDBEdit, TDBNavigator, TDBText, TDBComboBox, TDBLookupComboBox, TDBMemo, TDBImage
TCardPanel, TSearchBox, TSplitView, TToggleSwitch, TActivityIndicator, TRelativePanel, TStackPanel, TNumberBox, TEdgeBrowser (WebView2), TVirtualImageList + TImageCollection (HighDPI)
33.3 Event Handling and Form Lifecycle
Form events in order: OnCreate → OnShow → OnActivate → OnPaint ... OnCloseQuery → OnClose (Action: caFree, caHide, caMinimize, caNone) → OnDestroy.
Creating forms dynamically:
Remove auto-created forms in Project → Options → Forms, and create them on demand to save memory and startup time.
procedure TMainForm.FormCreate(Sender: TObject);
begin
Caption := 'Customer Manager';
cboCity.Items.AddStrings(['Pune', 'Mumbai', 'Delhi']);
cboCity.ItemIndex := 0;
end;
procedure TMainForm.btnAddClick(Sender: TObject);
begin
if Trim(edtName.Text) = '' then
begin
MessageDlg('Please enter a name.', mtWarning, [mbOK], 0);
edtName.SetFocus;
Exit;
end;
lstCustomers.Items.Add(Format('%s (%s)', [edtName.Text, cboCity.Text]));
edtName.Clear;
StatusBar1.SimpleText := Format('%d customers', [lstCustomers.Count]);
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := MessageDlg('Exit?', mtConfirmation, [mbYes, mbNo], 0) = mrYes;
end;
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = VK_F5) then RefreshData; // KeyPreview := True on the form
end;var Dlg := TSettingsForm.Create(nil);
try
Dlg.UserName := CurrentUser;
if Dlg.ShowModal = mrOk then CurrentUser := Dlg.UserName;
finally
Dlg.Free;
end;33.4 Actions, Menus and Layout
TActionList / TActionManager: centralize commands (Caption, ShortCut, ImageIndex, OnExecute, OnUpdate for enabling/disabling). Link actions to buttons and menu items.
Layout: Align (alTop, alClient...), Anchors, Constraints, Margins/AlignWithMargins, TGridPanel, TFlowPanel, TRelativePanel, TStackPanel. HighDPI (per-monitor v2) with TVirtualImageList.
33.5 Frames and Data Modules
TFrame: reusable composite UI pieces (like user controls) designed visually and dropped on forms.
TDataModule: a non-visual container for database connections, queries, actions, and business components, shared between forms. It separates data access from the UI.