unit label_form; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; const limit = 3; cWidth = 100; cHeight = 35; type TLabelGrid = array[0..limit, 0..limit] of TLabel; { TpropertiesForm } TpropertiesForm = class(TForm) cgFontStyle: TCheckGroup; rgAlignment: TRadioGroup; rgLayout: TRadioGroup; procedure cgFontStyleItemClick(Sender: TObject; Index: integer); procedure FormCreate(Sender: TObject); procedure rgAlignmentClick(Sender: TObject); procedure rgLayoutClick(Sender: TObject); private labelGrid: TLabelGrid; procedure SetupLabelGrid; function CreateLabel(aCol, aRow: integer): TLabel; end; var propertiesForm: TpropertiesForm; implementation {$R *.lfm} { TpropertiesForm } procedure TpropertiesForm.FormCreate(Sender: TObject); begin SetupLabelGrid; end; procedure TpropertiesForm.cgFontStyleItemClick(Sender: TObject; Index: integer); var c, r :integer; fs: TFontStyle; begin fs := TFontStyle(Index); for c := 0 to limit do for r := 0 to limit do if cgFontStyle.Checked[Index] then labelGrid[c, r].Font.Style := labelGrid[c, r].Font.Style + [fs] else labelGrid[c, r].Font.Style := labelGrid[c, r].Font.Style - [fs]; end; procedure TpropertiesForm.rgAlignmentClick(Sender: TObject); var rg: TRadioGroup; c, r, idx: integer; alignment: TAlignment; begin rg := TRadioGroup(Sender); // Cast sender object to its concrete type idx := rg.ItemIndex; alignment := TAlignment(idx); for c := 0 to limit do for r := 0 to limit do labelGrid[c, r].Alignment := alignment; end; procedure TpropertiesForm.rgLayoutClick(Sender: TObject); var rg: TRadioGroup; c, r, idx: integer; layout: TTextLayout; begin rg := TRadioGroup(Sender); idx := rg.ItemIndex; layout := TTextLayout(idx); for c := 0 to limit do for r := 0 to limit do labelGrid[c, r].Layout := layout; end; function TpropertiesForm.CreateLabel(aCol, aRow: integer): TLabel; var sum: integer; begin result := TLabel.Create(Self); result.Parent := Self; result.Caption := Format('col: %d, row: %d', [aCol, aRow]); result.AutoSize := False; result.SetBounds(aCol * cWidth, aRow * cHeight, cWidth, cHeight); sum := aCol + aRow; if (sum = 1) then sum := 4; result.Color := clInfoBk + sum; end; procedure TpropertiesForm.SetupLabelGrid; var c, r : Integer; begin for c := 0 to limit do for r:= 0 to limit do begin labelGrid[c, r] := CreateLabel(c, r); end; end; end.