summaryrefslogtreecommitdiff
path: root/examples/gui/modalforms/modalforms.lpr
blob: 188985e966854a6f4f7c478e55ee1996c879fc6c (plain)
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
{
  Demo of modal forms in action.
  
  NOTE:    Model form are not 100% implemented yet!
}
program modalforms;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  fpgfx,
  gui_form,
  gui_dialogs,
  gui_button,
  gui_label,
  gui_popupcalendar,
  gui_combobox,
  gui_edit;
  
type
  // forward declaration
  TForm1 = class;
  TForm2 = class;

  TMainForm = class(TfpgForm)
  private
    cal: TfpgComboBox;
    btnClose: TfpgButton;
    btnOpenForm1: TfpgButton;
    edtTest: TfpgEdit;
    procedure   btnCloseClick(Sender: TObject);
    procedure   btnOpenForm1Click(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
  end;
  

  TForm1 = class(TfpgForm)
  private
    cal: TfpgComboBox;
    Label1: TfpgLabel;
    btnClose: TfpgButton;
    btnOpenForm2: TfpgButton;
    edtTest: TfpgEdit;
    procedure   btnCloseClick(Sender: TObject);
    procedure   btnOpenForm2Click(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
  end;
  
  
  TForm2 = class(TfpgForm)
  private
    Label1: TfpgLabel;
    btnClose: TfpgButton;
    edtTest: TfpgEdit;
    procedure   btnCloseClick(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
  end;


{ TForm2 }

procedure TForm2.btnCloseClick(Sender: TObject);
begin
  Close;
end;

constructor TForm2.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  WindowTitle := 'Form2';
  Sizeable := False;
  SetPosition(200, 200, 200, 200);

  Label1 := CreateLabel(self, 10, 10, 'This is Form2');

  btnClose := CreateButton(self, 110, 170, 80, 'Quit', @btnCloseClick);
  btnClose.ImageName := 'stdimg.Quit';
  btnClose.ShowImage := True;
  
  edtTest := CreateEdit(self, 10, 60, 100, 23);

end;

{ TForm1 }

procedure TForm1.btnCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.btnOpenForm2Click(Sender: TObject);
var
  frm: TForm2;
begin
  frm := TForm2.Create(nil);
  try
    frm.ShowModal;
    writeln('Form2: This should only appear after the form closes.');
    edtTest.SetFocus;
    ActivateWindow;
  finally
    frm.Free;
  end;
end;

constructor TForm1.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  WindowTitle := 'Form1';
  Sizeable := False;
  SetPosition(150, 150, 200, 200);

  Label1 := CreateLabel(self, 10, 10, 'This is Form1');
  
  btnClose := CreateButton(self, 110, 170, 80, 'Quit', @btnCloseClick);
  btnClose.ImageName := 'stdimg.Quit';
  btnClose.ShowImage := True;
  
  btnOpenForm2 := CreateButton(self, 70, 100, 80, 'Open Form2', @btnOpenForm2Click);
  
  cal := TfpgComboBox.Create(self);
  cal.SetPosition(10, 10, 120, 23);
  
  edtTest := CreateEdit(self, 10, 60, 100, 23);

end;


{ TMainForm }

procedure TMainForm.btnCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.btnOpenForm1Click(Sender: TObject);
var
  frm: TForm1;
begin
  frm := TForm1.Create(nil);
  try
    frm.ShowModal;
    writeln('Form1: This should only appear after the form closes.');
    ActivateWindow;
  finally
    frm.Free;
  end;
end;

constructor TMainForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  WindowTitle := 'Modal Form Demo';
  Sizeable := False;
  SetPosition(100, 100, 400, 200);

  btnClose := CreateButton(self, 310, 170, 80, 'Quit', @btnCloseClick);
  btnClose.ImageName := 'stdimg.Quit';
  btnClose.ShowImage := True;
  
  btnOpenForm1 := CreateButton(self, 100, 100, 80, 'Open Form1', @btnOpenForm1Click);
  
  cal := TfpgComboBox.Create(self);
  cal.SetPosition(10, 10, 120, 23);
  
  edtTest := CreateEdit(self, 10, 60, 100, 23);
end;


procedure MainProc;
var
  frm: TMainForm;
begin
  fpgApplication.Initialize;
  frm := TMainForm.Create(nil);
  frm.Show;
  fpgApplication.Run;
  frm.Free;
end;

begin
  MainProc;
end.