1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
program gridtest;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,
SysUtils,
fpgfx,
gui_form,
gui_grid,
gui_button,
gui_checkbox,
gui_tab;
type
TMainForm = class(TfpgForm)
private
btnQuit: TfpgButton;
pagecontrol: TfpgPageControl;
tsTab1: TfpgTabSheet;
tsTab2: TfpgTabSheet;
grdMain: TfpgGrid;
stringgrid: TfpgStringGrid;
chkShowHeader: TfpgCheckBox;
chkShowGrid: TfpgCheckBox;
chkRowSelect: TfpgCheckBox;
chkDisabled: TfpgCheckBox;
procedure chkDisabledChange(Sender: TObject);
procedure chkRowSelectChange(Sender: TObject);
procedure chkShowHeaderChange(Sender: TObject);
procedure chkShowGridChange(Sender: TObject);
procedure btnQuitClick(Sender: TObject);
protected
procedure HandleShow; override;
public
constructor Create(AOwner: TComponent); override;
end;
{ TMainForm }
procedure TMainForm.chkDisabledChange(Sender: TObject);
begin
grdMain.Enabled := not chkDisabled.Checked;
stringgrid.Enabled := grdMain.Enabled;
end;
procedure TMainForm.chkRowSelectChange(Sender: TObject);
begin
grdMain.RowSelect := chkRowSelect.Checked;
stringgrid.RowSelect := grdMain.RowSelect;
end;
procedure TMainForm.chkShowHeaderChange(Sender: TObject);
begin
grdMain.ShowHeader := chkShowHeader.Checked;
stringgrid.ShowHeader := grdMain.ShowHeader;
end;
procedure TMainForm.chkShowGridChange(Sender: TObject);
begin
grdMain.ShowGrid := chkShowGrid.Checked;
stringgrid.ShowGrid := grdMain.ShowGrid;
end;
procedure TMainForm.btnQuitClick(Sender: TObject);
begin
Close;
end;
procedure TMainForm.HandleShow;
begin
inherited HandleShow;
end;
constructor TMainForm.Create(AOwner: TComponent);
var
c: integer;
r: integer;
begin
inherited Create(AOwner);
WindowTitle := 'Grid control test';
SetPosition(100, 100, 566, 350);
btnQuit := CreateButton(self, 476, 320, 80, 'Quit', @btnQuitClick);
btnQuit.ImageName := 'stdimg.Quit';
btnQuit.ShowImage := True;
btnQuit.Anchors := [anRight, anBottom];
pagecontrol := TfpgPageControl.Create(self);
pagecontrol.SetPosition(10, 10, Width-20, 300);
pagecontrol.Anchors := [anLeft, anTop, anRight, anBottom];
tsTab1 := TfpgTabSheet.Create(pagecontrol);
tsTab1.Text := 'Base Grid';
grdMain := TfpgGrid.Create(tsTab1);
grdMain.SetPosition(10, 10, Width-50, 250);
// grdMain.Anchors := [anLeft, anTop, anRight, anBottom];
grdMain.RowCount := 25;
for c := 1 to grdMain.ColumnCount do
grdMain.Columns[c-1].Title := 'Title ' + IntToStr(c);
tsTab2 := pagecontrol.AppendTabSheet('String Grid');
stringgrid := TfpgStringGrid.Create(tsTab2);
stringgrid.SetPosition(10, 10, Width-50, 250);
// change row and column count to something different that the default
stringgrid.ColumnCount := 2;
stringgrid.RowCount := 3;
// add and change a column
stringgrid.AddColumn('Extra', 100);
stringgrid.ColumnWidth[3] := 150;
// changes header text in different ways
stringgrid.ColumnTitle[1] := 'Column 1';
stringgrid.Columns[2].Title := 'Col 2';
// add some text
stringgrid.Cells[2, 3] := 'Hello';
stringgrid.Cells[3, 1] := '(r1,c3)';
// stringgrid.Anchors := [anLeft, anTop, anRight, anBottom];
pagecontrol.ActivePageIndex := 0;
chkShowHeader := CreateCheckBox(self, 10, 320, 'Show Header');
chkShowHeader.Checked := True;
chkShowHeader.OnChange := @chkShowHeaderChange;
chkShowHeader.Anchors := [anLeft, anBottom];
chkShowGrid := CreateCheckBox(self, chkShowHeader.Right+10, 320, 'Show Grid');
chkShowGrid.Checked := True;
chkShowGrid.OnChange := @chkShowGridChange;
chkShowGrid.Anchors := [anLeft, anBottom];
chkRowSelect := CreateCheckBox(self, chkShowGrid.Right+10, 320, 'Row Select');
chkRowSelect.Checked := False;
chkRowSelect.OnChange := @chkRowSelectChange;
chkRowSelect.Anchors := [anLeft, anBottom];
chkDisabled := CreateCheckBox(self, chkRowSelect.Right+10, 320, 'Disabled');
chkDisabled.Checked := False;
chkDisabled.OnChange := @chkDisabledChange;
chkDisabled.Anchors := [anLeft, anBottom];
end;
procedure MainProc;
var
frm: TMainForm;
begin
fpgApplication.Initialize;
frm := TMainForm.Create(nil);
frm.Show;
fpgApplication.Run;
end;
begin
MainProc;
end.
|