From bc0c83aee08846329865b8cc1bb541a37e187bfd Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 16 Mar 2010 10:29:08 +0200 Subject: Embedded Form example: extended the demo to test more options. Two embedded buttons are now added. One showing the embedded form visible by default. The other loading the embedded form visible = false by default. Also added a statement that prints a component hierarchy showing the value of Visible - for debug purposes. --- examples/gui/embedded_form/fra_test.pas | 9 ++- examples/gui/embedded_form/frm_main.pas | 114 +++++++++++++++++++++++++++----- 2 files changed, 103 insertions(+), 20 deletions(-) diff --git a/examples/gui/embedded_form/fra_test.pas b/examples/gui/embedded_form/fra_test.pas index 33c6a1c5..184ee2da 100644 --- a/examples/gui/embedded_form/fra_test.pas +++ b/examples/gui/embedded_form/fra_test.pas @@ -66,8 +66,9 @@ begin {%region 'Auto-generated GUI code' -fold} {@VFD_BODY_BEGIN: MyFrame} Name := 'MyFrame'; - SetPosition(380, 237, 200, 199); + SetPosition(380, 237, 200, 203); WindowTitle := 'MyFrame'; + Hint := ''; fraCheckBox1 := TfpgCheckBox.Create(self); with fraCheckBox1 do @@ -75,6 +76,7 @@ begin Name := 'fraCheckBox1'; SetPosition(8, 40, 120, 20); FontDesc := '#Label1'; + Hint := ''; TabOrder := 0; Text := 'CheckBox'; end; @@ -94,7 +96,7 @@ begin with Button1 do begin Name := 'Button1'; - SetPosition(104, 152, 80, 24); + SetPosition(104, 164, 80, 24); Anchors := [anRight,anBottom]; Text := 'Button'; FontDesc := '#Label1'; @@ -107,8 +109,9 @@ begin with Memo1 do begin Name := 'Memo1'; - SetPosition(12, 60, 172, 84); + SetPosition(12, 60, 172, 88); Anchors := [anLeft,anRight,anTop,anBottom]; + Hint := ''; Lines.Add(''); FontDesc := '#Edit1'; TabOrder := 3; diff --git a/examples/gui/embedded_form/frm_main.pas b/examples/gui/embedded_form/frm_main.pas index 7cb28f6c..831385cc 100644 --- a/examples/gui/embedded_form/frm_main.pas +++ b/examples/gui/embedded_form/frm_main.pas @@ -17,15 +17,17 @@ type BorderBevel: TfpgBevel; Container: TfpgBevel; btnExternal: TfpgButton; - btnEmbedded: TfpgButton; + btnEmbed1: TfpgButton; CheckBox1: TfpgCheckBox; MainMenu: TfpgMenubar; mnuFile: TfpgPopupMenu; mnuHelp: TfpgPopupMenu; + btnEmbed2: TfpgButton; {@VFD_HEAD_END: MainForm} frame: TMyFrame; procedure btnExternalClicked(Sender: TObject); - procedure btnEmbeddedClicked(Sender: TObject); + procedure btnEmbed1Clicked(Sender: TObject); + procedure btnEmbed2Clicked(Sender: TObject); procedure CheckBoxChanged(Sender: TObject); procedure miQuitClicked(Sender: TObject); procedure miHelpAboutClicked(Sender: TObject); @@ -41,11 +43,49 @@ 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 - frame.Visible := Checkbox1.Checked; + if Assigned(frame) then + begin + frame.Visible := Checkbox1.Checked; + writeln('Checkbox clicked...'); + PrintVisibleState(self); + end; end; procedure TMainForm.miQuitClicked(Sender: TObject); @@ -80,7 +120,7 @@ begin end; end; -procedure TMainForm.btnEmbeddedClicked(Sender: TObject); +procedure TMainForm.btnEmbed1Clicked(Sender: TObject); begin if Assigned(frame) then exit; @@ -92,11 +132,33 @@ begin SetPosition(0, 0, 280, 196); Shape := bsSpacer; Align := alClient; - Visible := True; 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); + Shape := bsSpacer; + Align := alClient; + Visible := False; + end; + PrintVisibleState(self); + + CheckBox1.Enabled := True; + CheckBox1.Checked := False; + btnEmbed1.Enabled := False; end; procedure TMainForm.AfterCreate; @@ -104,15 +166,18 @@ begin {%region 'Auto-generated GUI code' -fold} {@VFD_BODY_BEGIN: MainForm} Name := 'MainForm'; - SetPosition(387, 207, 300, 340); + SetPosition(387, 207, 393, 340); WindowTitle := 'MainForm'; + Hint := ''; + ShowHint := True; BorderBevel := TfpgBevel.Create(self); with BorderBevel do begin Name := 'BorderBevel'; - SetPosition(0, 68, 300, 272); + SetPosition(0, 68, 393, 272); Anchors := [anLeft,anRight,anTop,anBottom]; + Hint := ''; Shape := bsSpacer; end; @@ -120,8 +185,9 @@ begin with Container do begin Name := 'Container'; - SetPosition(8, 8, 284, 257); + SetPosition(8, 8, 377, 257); Anchors := [anLeft,anRight,anTop,anBottom]; + Hint := ''; Style := bsLowered; Shape := bsSpacer; end; @@ -139,25 +205,26 @@ begin OnClick := @btnExternalClicked; end; - btnEmbedded := TfpgButton.Create(self); - with btnEmbedded do + btnEmbed1 := TfpgButton.Create(self); + with btnEmbed1 do begin - Name := 'btnEmbedded'; - SetPosition(100, 40, 80, 24); - Text := 'Embedded'; + Name := 'btnEmbed1'; + SetPosition(96, 40, 80, 24); + Text := 'Embed 1'; FontDesc := '#Label1'; - Hint := ''; + Hint := 'Create embedded Form with Visible = True (default behaviour)'; ImageName := ''; TabOrder := 2; - OnClick := @btnEmbeddedClicked; + OnClick := @btnEmbed1Clicked; end; CheckBox1 := TfpgCheckBox.Create(self); with CheckBox1 do begin Name := 'CheckBox1'; - SetPosition(192, 40, 93, 20); + SetPosition(296, 40, 93, 20); FontDesc := '#Label1'; + Hint := ''; TabOrder := 4; Text := 'Visible'; Enabled := false; @@ -168,7 +235,7 @@ begin with MainMenu do begin Name := 'MainMenu'; - SetPosition(0, 0, 300, 28); + SetPosition(0, 0, 393, 28); Anchors := [anLeft,anRight,anTop]; end; @@ -188,6 +255,19 @@ begin 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; -- cgit v1.2.3-70-g09d2