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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
unit frm_main;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes,
fpg_base, fpg_main, fpg_form, fpg_panel, fpg_button,
fpg_checkbox, fra_test, fpg_menu;
type
TMainForm = class(TfpgForm)
private
{@VFD_HEAD_BEGIN: MainForm}
BorderBevel: TfpgBevel;
Container: TfpgBevel;
btnExternal: TfpgButton;
btnEmbed1: TfpgButton;
CheckBox1: TfpgCheckBox;
MainMenu: TfpgMenubar;
mnuFile: TfpgPopupMenu;
mnuHelp: TfpgPopupMenu;
btnEmbed2: TfpgButton;
{@VFD_HEAD_END: MainForm}
frame: TMyFrame;
procedure btnExternalClicked(Sender: TObject);
procedure btnEmbed1Clicked(Sender: TObject);
procedure btnEmbed2Clicked(Sender: TObject);
procedure CheckBoxChanged(Sender: TObject);
procedure miQuitClicked(Sender: TObject);
procedure miHelpAboutClicked(Sender: TObject);
public
procedure AfterCreate; override;
end;
{@VFD_NEWFORM_DECL}
implementation
uses
fpg_widget, fpg_dialogs;
var
{ manage indentation level }
indent: integer = 0;
{ Output component hierarchy and status of each component's Visible property }
procedure PrintVisibleState(AComponent: TfpgWidget);
var
i: integer;
{ Create string equal to indentation level }
function Spaces: string;
var
j: integer;
begin
if indent = 0 then
exit;
for j := 1 to indent do
Result := Result + ' ';
end;
begin
writeln(Spaces + AComponent.ClassName + ' - [parent]: ' + BoolToStr(AComponent.Visible, True));
Inc(indent, 2);
for i := 0 to AComponent.ComponentCount-1 do
begin
if AComponent.Components[i].ComponentCount > 0 then
PrintVisibleState(TfpgWidget(AComponent.Components[i]))
else
writeln(Spaces + AComponent.Components[i].ClassName + ': ' + BoolToStr(TfpgWidget(AComponent.Components[i]).Visible, True));
end;
dec(indent, 2);
end;
{@VFD_NEWFORM_IMPL}
procedure TMainForm.CheckBoxChanged(Sender: TObject);
begin
if Assigned(frame) then
begin
frame.Visible := Checkbox1.Checked;
writeln('Checkbox clicked...');
PrintVisibleState(self);
end;
end;
procedure TMainForm.miQuitClicked(Sender: TObject);
begin
Close;
end;
procedure TMainForm.miHelpAboutClicked(Sender: TObject);
begin
TfpgMessageDialog.Information('Embedded Frame Demo', 'A simple demo showing how to embed frames')
end;
procedure TMainForm.btnExternalClicked(Sender: TObject);
var
frm: TfpgForm;
fra: TMyFrame;
begin
{ create a form at runtime that will hold our frame. }
frm := TfpgForm.Create(nil);
try
frm.WindowPosition := wpOneThirdDown;
frm.Width := 284;
frm.Height := 257;
// embed the frame in the form
fra := TMyFrame.Create(frm);
fra.Align := alClient;
frm.ShowModal;
finally
frm.Free;
end;
end;
procedure TMainForm.btnEmbed1Clicked(Sender: TObject);
begin
if Assigned(frame) then
exit;
frame := TMyFrame.Create(Container);
with frame do
begin
Name := 'frame';
SetPosition(0, 0, 280, 196);
Align := alClient;
end;
PrintVisibleState(self);
CheckBox1.Enabled := True;
CheckBox1.Checked := True;
btnEmbed2.Enabled := False;
end;
procedure TMainForm.btnEmbed2Clicked(Sender: TObject);
begin
if Assigned(frame) then
exit;
frame := TMyFrame.Create(Container);
with frame do
begin
Name := 'frame';
SetPosition(0, 0, 280, 196);
Align := alClient;
Visible := False;
end;
PrintVisibleState(self);
CheckBox1.Enabled := True;
CheckBox1.Checked := False;
btnEmbed1.Enabled := False;
end;
procedure TMainForm.AfterCreate;
begin
{%region 'Auto-generated GUI code' -fold}
{@VFD_BODY_BEGIN: MainForm}
Name := 'MainForm';
SetPosition(387, 207, 393, 340);
WindowTitle := 'MainForm';
Hint := '';
ShowHint := True;
BorderBevel := TfpgBevel.Create(self);
with BorderBevel do
begin
Name := 'BorderBevel';
SetPosition(0, 68, 393, 272);
Anchors := [anLeft,anRight,anTop,anBottom];
Hint := '';
Shape := bsSpacer;
end;
Container := TfpgBevel.Create(BorderBevel);
with Container do
begin
Name := 'Container';
SetPosition(8, 8, 377, 257);
Anchors := [anLeft,anRight,anTop,anBottom];
Hint := '';
Style := bsLowered;
Shape := bsSpacer;
end;
btnExternal := TfpgButton.Create(self);
with btnExternal do
begin
Name := 'btnExternal';
SetPosition(12, 40, 80, 24);
Text := 'External';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 1;
OnClick := @btnExternalClicked;
end;
btnEmbed1 := TfpgButton.Create(self);
with btnEmbed1 do
begin
Name := 'btnEmbed1';
SetPosition(96, 40, 80, 24);
Text := 'Embed 1';
FontDesc := '#Label1';
Hint := 'Create embedded Form with Visible = True (default behaviour)';
ImageName := '';
TabOrder := 2;
OnClick := @btnEmbed1Clicked;
end;
CheckBox1 := TfpgCheckBox.Create(self);
with CheckBox1 do
begin
Name := 'CheckBox1';
SetPosition(296, 40, 93, 20);
FontDesc := '#Label1';
Hint := '';
TabOrder := 4;
Text := 'Visible';
Enabled := false;
OnChange := @CheckBoxChanged;
end;
MainMenu := TfpgMenubar.Create(self);
with MainMenu do
begin
Name := 'MainMenu';
SetPosition(0, 0, 393, 28);
Anchors := [anLeft,anRight,anTop];
end;
mnuFile := TfpgPopupMenu.Create(self);
with mnuFile do
begin
Name := 'mnuFile';
SetPosition(156, 88, 120, 20);
AddMenuItem('Quit', '', @miQuitClicked);
end;
mnuHelp := TfpgPopupMenu.Create(self);
with mnuHelp do
begin
Name := 'mnuHelp';
SetPosition(156, 112, 120, 20);
AddMenuItem('About...', '', @miHelpAboutClicked);
end;
btnEmbed2 := TfpgButton.Create(self);
with btnEmbed2 do
begin
Name := 'btnEmbed2';
SetPosition(180, 40, 80, 24);
Text := 'Embed 2';
FontDesc := '#Label1';
Hint := 'Create embedded Form with Visible = False';
ImageName := '';
TabOrder := 7;
OnClick := @btnEmbed2Clicked;
end;
{@VFD_BODY_END: MainForm}
{%endregion}
MainMenu.AddMenuItem('File', nil).SubMenu := mnuFile;
MainMenu.AddMenuItem('Help', nil).SubMenu := mnuHelp;
end;
end.
|