Appendix G: Lazarus Component Reference

This appendix provides a quick reference for the most important visual and non-visual components available in the Lazarus Component Library (LCL). For each component, you will find its purpose, key properties, key events, and a common usage pattern. Components are organized by their palette tab in the Lazarus IDE.


G.1 Standard Tab

These are the most frequently used components, found on the "Standard" tab of the component palette.

TButton

A standard push button that triggers an action when clicked.

Key Properties:

Property Type Description
Caption String Text displayed on the button
Default Boolean If True, pressing Enter activates this button
Cancel Boolean If True, pressing Escape activates this button
Enabled Boolean Whether the button can be clicked
ModalResult TModalResult Automatically closes a modal dialog and returns this result

Key Events:

Event Description
OnClick Fires when the button is clicked

Common Usage:

procedure TForm1.btnCalculateClick(Sender: TObject);
begin
  lblResult.Caption := IntToStr(StrToInt(edtA.Text) + StrToInt(edtB.Text));
end;

TLabel

Displays static text. The user cannot edit it directly.

Key Properties:

Property Type Description
Caption String The displayed text
Font TFont Font settings (name, size, color, style)
Alignment TAlignment Text alignment: taLeftJustify, taCenter, taRightJustify
WordWrap Boolean Wrap text to fit the label width
AutoSize Boolean Automatically resize to fit the text
FocusControl TWinControl Associated control (for & accelerator keys)

Common Usage:

lblStatus.Caption := 'Processing... ' + IntToStr(Progress) + '%';
lblStatus.Font.Color := clRed;

TEdit

A single-line text input field.

Key Properties:

Property Type Description
Text String The current text content
MaxLength Integer Maximum characters allowed (0 = unlimited)
ReadOnly Boolean Prevents user editing
PasswordChar Char If set, masks input (e.g., *)
CharCase TEditCharCase Force ecUpperCase, ecLowerCase, or ecNormal
NumbersOnly Boolean Accept only digit characters

Key Events:

Event Description
OnChange Fires whenever the text changes
OnKeyPress Fires when a key is pressed (character parameter)
OnEnter Fires when the control receives focus
OnExit Fires when the control loses focus

Common Usage:

procedure TForm1.edtSearchChange(Sender: TObject);
begin
  FilterList(edtSearch.Text);
end;

TMemo

A multi-line text editing control.

Key Properties:

Property Type Description
Lines TStrings The text content as a string list
Text String All text as a single string (with line endings)
ScrollBars TScrollStyle ssNone, ssVertical, ssHorizontal, ssBoth
WordWrap Boolean Wrap long lines
ReadOnly Boolean Prevents user editing
MaxLength Integer Maximum characters (0 = unlimited)

Key Events:

Event Description
OnChange Fires when text changes

Common Usage:

{ Load a file into the memo }
mmoLog.Lines.LoadFromFile('log.txt');

{ Append a line }
mmoLog.Lines.Add('Operation completed at ' + TimeToStr(Now));

{ Save to file }
mmoLog.Lines.SaveToFile('log.txt');

{ Clear }
mmoLog.Clear;

TComboBox

A dropdown list, optionally allowing the user to type custom text.

Key Properties:

Property Type Description
Items TStrings The list of selectable items
ItemIndex Integer Index of the currently selected item (-1 = none)
Text String The displayed/typed text
Style TComboBoxStyle csDropDown (editable), csDropDownList (select only), csOwnerDrawFixed, etc.
Sorted Boolean Automatically sort items alphabetically
DropDownCount Integer Max visible items when dropped down

Key Events:

Event Description
OnChange Fires when the selection or text changes
OnSelect Fires when an item is selected from the dropdown

Common Usage:

{ Populate at runtime }
cboCountry.Items.Clear;
cboCountry.Items.Add('United States');
cboCountry.Items.Add('Canada');
cboCountry.Items.Add('Mexico');
cboCountry.ItemIndex := 0;

{ Read the selected value }
SelectedCountry := cboCountry.Items[cboCountry.ItemIndex];

TCheckBox

A toggle control with a check mark.

Key Properties:

Property Type Description
Caption String Label text next to the checkbox
Checked Boolean Whether the box is checked
State TCheckBoxState cbUnchecked, cbChecked, cbGrayed
AllowGrayed Boolean Enable a third (grayed/indeterminate) state

Key Events:

Event Description
OnChange Fires when the checked state changes

Common Usage:

procedure TForm1.chkBoldChange(Sender: TObject);
begin
  if chkBold.Checked then
    mmoEditor.Font.Style := mmoEditor.Font.Style + [fsBold]
  else
    mmoEditor.Font.Style := mmoEditor.Font.Style - [fsBold];
end;

TRadioButton

A mutually exclusive option button. Only one radio button in a group (same parent container) can be selected at a time.

Key Properties:

Property Type Description
Caption String Label text
Checked Boolean Whether this button is selected

Key Events:

Event Description
OnChange Fires when the selection state changes

Common Usage:

if rbSmall.Checked then
  FontSize := 10
else if rbMedium.Checked then
  FontSize := 14
else if rbLarge.Checked then
  FontSize := 20;

Use a TRadioGroup or TGroupBox to create multiple independent groups of radio buttons on the same form.


TListBox

A scrollable list of text items from which the user can select one or more.

Key Properties:

Property Type Description
Items TStrings The list of items
ItemIndex Integer Index of the selected item (-1 = none)
MultiSelect Boolean Allow multiple items to be selected
Selected[Index] Boolean Whether a specific item is selected (for multi-select)
Sorted Boolean Auto-sort items alphabetically
Count Integer Number of items (read-only, via Items.Count)

Key Events:

Event Description
OnSelectionChange Fires when the selection changes
OnDblClick Fires when an item is double-clicked

Common Usage:

{ Add items }
lstFiles.Items.Add('report.txt');
lstFiles.Items.Add('data.csv');

{ Read selected item }
if lstFiles.ItemIndex >= 0 then
  OpenFile(lstFiles.Items[lstFiles.ItemIndex]);

{ Iterate selected items (multi-select) }
for I := 0 to lstFiles.Items.Count - 1 do
  if lstFiles.Selected[I] then
    ProcessFile(lstFiles.Items[I]);

TGroupBox

A container that visually groups related controls with a labeled border.

Key Properties:

Property Type Description
Caption String Text displayed in the border

Place radio buttons, checkboxes, or other controls inside a TGroupBox to group them visually and logically.


TRadioGroup

A group box specifically designed for radio buttons. Manages mutual exclusion automatically.

Key Properties:

Property Type Description
Items TStrings The radio button labels
ItemIndex Integer Index of the selected radio button (-1 = none)
Columns Integer Number of columns for layout
Caption String Group title

Common Usage:

{ Set up at design time via Items property, or at runtime: }
rgSize.Items.Clear;
rgSize.Items.Add('Small');
rgSize.Items.Add('Medium');
rgSize.Items.Add('Large');
rgSize.ItemIndex := 1;   { Select 'Medium' }

{ Read selection }
case rgSize.ItemIndex of
  0: ApplySmall;
  1: ApplyMedium;
  2: ApplyLarge;
end;

G.2 Additional Tab

TBitBtn

A button that displays both an image (glyph) and text.

Key Properties:

Property Type Description
Caption String Button text
Glyph TBitmap Image displayed on the button
Kind TBitBtnKind Predefined button type: bkOK, bkCancel, bkYes, bkNo, bkHelp, bkClose, etc.
Layout TButtonLayout Image position: blGlyphLeft, blGlyphRight, blGlyphTop, blGlyphBottom
Spacing Integer Pixels between glyph and caption

Setting Kind automatically sets the Caption, Glyph, and ModalResult.


TSpeedButton

A flat, toolbar-style button. Does not receive focus. Often used in groups for toggle functionality.

Key Properties:

Property Type Description
GroupIndex Integer Buttons with the same GroupIndex > 0 form a toggle group
Down Boolean Whether the button is pressed (for toggle buttons)
AllowAllUp Boolean If True, all buttons in the group can be unpressed
Flat Boolean Button appears flat until mouse hovers
Glyph TBitmap Button image

TImage

Displays an image (bitmap, PNG, JPEG, icon, etc.).

Key Properties:

Property Type Description
Picture TPicture The image to display
Stretch Boolean Scale image to fill the control
Proportional Boolean Maintain aspect ratio when stretching
Center Boolean Center the image in the control
Transparent Boolean Make the background color transparent

Common Usage:

{ Load an image from file }
Image1.Picture.LoadFromFile('photo.png');

{ Load from resource }
Image1.Picture.LoadFromResourceName(HInstance, 'LOGO');

TShape

Draws a simple geometric shape (rectangle, circle, ellipse, rounded rectangle, etc.).

Key Properties:

Property Type Description
Shape TShapeType stRectangle, stCircle, stEllipse, stRoundRect, stSquare, stRoundSquare, stTriangle
Brush TBrush Fill color and style
Pen TPen Border color, width, and style

TMaskEdit

A text input that enforces a specific format using an input mask.

Key Properties:

Property Type Description
EditMask String The input mask (e.g., '(999) 000-0000;1;_' for US phone)
Text String The formatted text including mask literals
EditText String The raw text without mask literals

Mask Characters:

Char Meaning
0 Required digit
9 Optional digit
A Required letter
a Optional letter
L Required letter (uppercase)
> All following characters uppercase
< All following characters lowercase

TStringGrid

A grid of cells that displays and optionally edits text in a spreadsheet-like layout.

Key Properties:

Property Type Description
ColCount Integer Number of columns
RowCount Integer Number of rows
FixedCols Integer Number of fixed (header) columns
FixedRows Integer Number of fixed (header) rows
Cells[Col, Row] String Text in a specific cell
Options TGridOptions Feature flags: goEditing, goRowSelect, goColSizing, etc.
DefaultColWidth Integer Default column width in pixels
DefaultRowHeight Integer Default row height in pixels

Key Events:

Event Description
OnSelectCell Fires when a cell is selected
OnSetEditText Fires when cell text is changed by user
OnDrawCell Custom cell drawing

Common Usage:

{ Set up a simple spreadsheet }
StringGrid1.ColCount := 4;
StringGrid1.RowCount := 11;
StringGrid1.FixedRows := 1;
StringGrid1.FixedCols := 1;

{ Set headers }
StringGrid1.Cells[0, 0] := '#';
StringGrid1.Cells[1, 0] := 'Name';
StringGrid1.Cells[2, 0] := 'Score';
StringGrid1.Cells[3, 0] := 'Grade';

{ Populate data }
for I := 1 to 10 do
begin
  StringGrid1.Cells[0, I] := IntToStr(I);
  StringGrid1.Cells[1, I] := Students[I].Name;
  StringGrid1.Cells[2, I] := IntToStr(Students[I].Score);
  StringGrid1.Cells[3, I] := Students[I].Grade;
end;

{ Enable editing }
StringGrid1.Options := StringGrid1.Options + [goEditing];

G.3 Common Dialogs Tab

These are non-visual components that display standard operating system dialogs when their Execute method is called. Execute returns True if the user confirmed the dialog, False if they canceled.

TOpenDialog

Displays the standard "Open File" dialog.

Key Properties:

Property Type Description
FileName String The selected file path (after Execute)
Filter String File type filter (e.g., 'Text files|*.txt|All files|*.*')
FilterIndex Integer Which filter is initially selected (1-based)
InitialDir String Starting directory
Title String Dialog title bar text
Options TOpenOptions Flags: ofAllowMultiSelect, ofFileMustExist, ofPathMustExist, etc.
Files TStrings All selected files (when multi-select is enabled)

Common Usage:

if OpenDialog1.Execute then
begin
  mmoEditor.Lines.LoadFromFile(OpenDialog1.FileName);
  Caption := 'Editor - ' + ExtractFileName(OpenDialog1.FileName);
end;

TSaveDialog

Displays the standard "Save File" dialog.

Key Properties: Same as TOpenDialog, plus:

Property Type Description
DefaultExt String Extension added if the user does not type one
Options TOpenOptions Includes ofOverwritePrompt to warn before overwriting

Common Usage:

SaveDialog1.DefaultExt := 'txt';
SaveDialog1.Filter := 'Text files|*.txt|All files|*.*';
if SaveDialog1.Execute then
  mmoEditor.Lines.SaveToFile(SaveDialog1.FileName);

TFontDialog

Displays the standard font selection dialog.

Key Properties:

Property Type Description
Font TFont The selected font (after Execute)

Common Usage:

FontDialog1.Font := mmoEditor.Font;
if FontDialog1.Execute then
  mmoEditor.Font := FontDialog1.Font;

TColorDialog

Displays the standard color picker dialog.

Key Properties:

Property Type Description
Color TColor The selected color (after Execute)

Common Usage:

ColorDialog1.Color := Panel1.Color;
if ColorDialog1.Execute then
  Panel1.Color := ColorDialog1.Color;

TSelectDirectoryDialog

Displays a directory (folder) picker. This is Lazarus-specific (Delphi uses a different approach).

Key Properties:

Property Type Description
FileName String The selected directory path
InitialDir String Starting directory
Title String Dialog title

G.4 Data Access Tab

These components provide database connectivity. The examples use SQLite, but the SQLDB framework supports PostgreSQL, MySQL, Oracle, ODBC, and others by substituting the connection component.

TSQLite3Connection

Provides a connection to a SQLite database file.

Key Properties:

Property Type Description
DatabaseName String Path to the .sqlite or .db file
Connected Boolean Open/close the connection

Common Usage:

SQLite3Connection1.DatabaseName := 'mydata.db';
SQLite3Connection1.Open;

You must have the SQLite library (sqlite3.dll on Windows, libsqlite3.so on Linux) available on your system.


TSQLTransaction

Manages database transactions. Required by SQLDB — every query must be associated with a transaction.

Key Properties:

Property Type Description
Database TDatabase The connection component
Active Boolean Whether a transaction is open

Key Methods:

Method Description
Commit Save all changes
Rollback Discard all changes
CommitRetaining Commit but keep the transaction open

TSQLQuery

Executes SQL statements and holds result sets.

Key Properties:

Property Type Description
Database TDatabase The connection component
Transaction TSQLTransaction The transaction component
SQL TStrings The SQL statement text
Active Boolean True when the query has a result set open
Params TParams Parameterized query values
FieldByName(Name) TField Access a column by name

Key Methods:

Method Description
Open Execute a SELECT query and open the result set
ExecSQL Execute an INSERT, UPDATE, DELETE, or DDL statement
Close Close the result set
First, Next, Prior, Last Navigate the result set
EOF True when past the last record

Common Usage:

{ Select query }
SQLQuery1.SQL.Text := 'SELECT id, name, email FROM customers WHERE active = :active';
SQLQuery1.Params.ParamByName('active').AsBoolean := True;
SQLQuery1.Open;

while not SQLQuery1.EOF do
begin
  WriteLn(SQLQuery1.FieldByName('name').AsString);
  SQLQuery1.Next;
end;
SQLQuery1.Close;

{ Insert query }
SQLQuery1.SQL.Text := 'INSERT INTO customers (name, email) VALUES (:name, :email)';
SQLQuery1.Params.ParamByName('name').AsString := 'Alice Smith';
SQLQuery1.Params.ParamByName('email').AsString := 'alice@example.com';
SQLQuery1.ExecSQL;
SQLTransaction1.Commit;

TDataSource

Acts as a bridge between a dataset (like TSQLQuery) and data-aware visual controls (like TDBGrid).

Key Properties:

Property Type Description
DataSet TDataSet The underlying dataset (TSQLQuery, etc.)
AutoEdit Boolean Automatically switch to edit mode when user types

G.5 Data Controls Tab

Data-aware controls automatically display and edit data from a TDataSource.

TDBGrid

Displays a dataset as a scrollable table with rows and columns.

Key Properties:

Property Type Description
DataSource TDataSource The data source to display
Columns TDBGridColumns Column definitions (title, width, field name)
Options TDBGridOptions Feature flags: dgEditing, dgRowSelect, dgIndicator, etc.
ReadOnly Boolean Prevent editing

Key Events:

Event Description
OnCellClick Fires when a cell is clicked
OnTitleClick Fires when a column header is clicked (use for sorting)

Common Usage:

{ Minimal setup: connect DataSource to the query, DBGrid to the DataSource }
DataSource1.DataSet := SQLQuery1;
DBGrid1.DataSource := DataSource1;
SQLQuery1.Open;    { Grid automatically populates }

TDBEdit

A single-line edit control bound to a database field.

Key Properties:

Property Type Description
DataSource TDataSource The data source
DataField String The field name to bind to

TDBMemo

A multi-line text control bound to a text or memo database field.

Key Properties:

Property Type Description
DataSource TDataSource The data source
DataField String The field name to bind to
ScrollBars TScrollStyle Scroll bar visibility

TDBNavigator

A toolbar with buttons for navigating and editing a dataset (First, Prior, Next, Last, Insert, Delete, Edit, Post, Cancel, Refresh).

Key Properties:

Property Type Description
DataSource TDataSource The data source to navigate
VisibleButtons TDBNavButtonSet Which buttons to show

Common Usage:

DBNavigator1.DataSource := DataSource1;
{ The navigator automatically enables/disables buttons based on the dataset state }

G.6 Common Patterns

Master-Detail Setup

Display a list of customers in one grid and their orders in another:

{ Master query }
qryCustomers.SQL.Text := 'SELECT * FROM customers';
qryCustomers.Open;

{ Detail query — filtered by the master's current record }
qryOrders.SQL.Text := 'SELECT * FROM orders WHERE customer_id = :customer_id';
qryOrders.DataSource := dsCustomers;   { Links to master }

{ The detail query re-executes automatically when the master record changes }

Creating a Form Programmatically

procedure TForm1.btnOpenClick(Sender: TObject);
var
  Dlg: TForm;
  Lbl: TLabel;
  Btn: TButton;
begin
  Dlg := TForm.CreateNew(Self);
  try
    Dlg.Caption := 'About';
    Dlg.Width := 300;
    Dlg.Height := 150;
    Dlg.Position := poMainFormCenter;

    Lbl := TLabel.Create(Dlg);
    Lbl.Parent := Dlg;
    Lbl.Caption := 'Programming with Pascal v1.0';
    Lbl.Left := 20;
    Lbl.Top := 20;

    Btn := TButton.Create(Dlg);
    Btn.Parent := Dlg;
    Btn.Caption := 'OK';
    Btn.ModalResult := mrOK;
    Btn.Left := 110;
    Btn.Top := 80;

    Dlg.ShowModal;
  finally
    Dlg.Free;
  end;
end;

Loading and Saving Settings with TIniFile

While not a visual component, TIniFile (from the IniFiles unit) is commonly used to save and restore control states:

uses
  IniFiles;

procedure SaveSettings;
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create('settings.ini');
  try
    Ini.WriteString('Window', 'Title', Form1.Caption);
    Ini.WriteInteger('Window', 'Width', Form1.Width);
    Ini.WriteInteger('Window', 'Height', Form1.Height);
    Ini.WriteBool('Options', 'WordWrap', chkWordWrap.Checked);
  finally
    Ini.Free;
  end;
end;

procedure LoadSettings;
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create('settings.ini');
  try
    Form1.Caption := Ini.ReadString('Window', 'Title', 'Untitled');
    Form1.Width := Ini.ReadInteger('Window', 'Width', 640);
    Form1.Height := Ini.ReadInteger('Window', 'Height', 480);
    chkWordWrap.Checked := Ini.ReadBool('Options', 'WordWrap', True);
  finally
    Ini.Free;
  end;
end;

G.7 Common Properties Shared by All Controls

Every visual control inherits from TControl and shares these properties:

Property Type Description
Name String Identifier used in code (e.g., btnOK, edtName)
Left Integer X position relative to parent
Top Integer Y position relative to parent
Width Integer Width in pixels
Height Integer Height in pixels
Visible Boolean Whether the control is visible
Enabled Boolean Whether the control is interactive
Hint String Tooltip text (requires ShowHint := True)
ShowHint Boolean Enable tooltip display
Cursor TCursor Mouse cursor when hovering
Color TColor Background color
Font TFont Text font
Align TAlign Docking: alNone, alTop, alBottom, alLeft, alRight, alClient
Anchors TAnchors Edge anchoring: [akLeft, akTop, akRight, akBottom]
Constraints TSizeConstraints Min/max width and height
Tag Integer General-purpose integer for programmer use
Parent TWinControl The container this control lives inside
PopupMenu TPopupMenu Right-click context menu
TabOrder Integer Tab key navigation order
TabStop Boolean Whether Tab key can focus this control

Common Events Shared by All Controls

Event Description
OnClick Mouse click or keyboard activation
OnDblClick Mouse double-click
OnMouseDown Mouse button pressed
OnMouseUp Mouse button released
OnMouseMove Mouse moved over the control
OnMouseEnter Mouse entered the control boundary
OnMouseLeave Mouse left the control boundary
OnKeyDown Key pressed (key code)
OnKeyUp Key released (key code)
OnKeyPress Key pressed (character)
OnResize Control was resized
OnPaint Control needs repainting
OnEnter Control received focus
OnExit Control lost focus

G.8 Naming Conventions

Lazarus uses a standard prefix convention for component names. Following these conventions makes code more readable:

Prefix Component Type Example
btn TButton, TBitBtn btnSave, btnCancel
lbl TLabel lblName, lblStatus
edt TEdit edtFirstName, edtSearch
mmo TMemo mmoNotes, mmoLog
cbo TComboBox cboCountry, cboFont
chk TCheckBox chkBold, chkActive
rb TRadioButton rbSmall, rbLarge
rg TRadioGroup rgAlignment, rgSize
lst TListBox lstFiles, lstStudents
grp TGroupBox grpOptions, grpFormat
img TImage imgLogo, imgPhoto
shp TShape shpIndicator
sg TStringGrid sgData, sgScores
dlgOpen TOpenDialog dlgOpen, dlgOpenImage
dlgSave TSaveDialog dlgSave, dlgSaveAs
dlgFont TFontDialog dlgFont
dlgColor TColorDialog dlgColor
ds TDataSource dsCustomers, dsOrders
qry TSQLQuery qryCustomers, qryOrders
conn TSQLite3Connection connMain
txn TSQLTransaction txnMain
dbg TDBGrid dbgCustomers
dbn TDBNavigator dbnCustomers
dbe TDBEdit dbeName, dbeEmail
dbm TDBMemo dbmNotes

This appendix covers the components you will use most frequently when building Lazarus applications. For the complete component reference, consult the Lazarus documentation at https://wiki.lazarus-ide.org/ and the LCL source code.