summaryrefslogtreecommitdiff
path: root/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas
blob: 1b6f27f709d4db5009f0a74a059dfc966fe466cc (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
192
193
194
195
196
197
198
199
200
unit frmCityMaint;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, fpg_base, fpg_main, fpg_edit,
  fpg_widget, fpg_form, fpg_label, fpg_button,
  fpg_dialogs, fpg_combobox,
  model, tiModelMediator;

type

  TCityEditForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: CityEditForm}
    lblName1: TfpgLabel;
    edName: TfpgEdit;
    lblName2: TfpgLabel;
    edZIP: TfpgEdit;
    lblName3: TfpgLabel;
    cbCountry: TfpgComboBox;
    btnSave: TfpgButton;
    btnCancel: TfpgButton;
    btnDebug: TfpgButton;
    {@VFD_HEAD_END: CityEditForm}
    FMediator: TtiModelMediator;
    FData: TCity;
    procedure SetData(const AValue: TCity);
    procedure SetupMediators;
    procedure btnDebugClicked(Sender: TObject);
  public
    procedure AfterCreate; override;
    property  Data: TCity read FData write SetData;
  end;

{@VFD_NEWFORM_DECL}

function EditCity(AData: TCity): boolean;


implementation

uses
  tiBaseMediator, contactmanager, typinfo, tiDialogs;


function EditCity(AData: TCity): boolean;
var
  frm: TCityEditForm;
begin
  frm:= TCityEditForm.Create(nil);
  try
    frm.SetData(AData);
    result:= frm.ShowModal = mrOK;
  finally
    frm.Free;
  end;
end;

{@VFD_NEWFORM_IMPL}

procedure TCityEditForm.SetData(const AValue: TCity);
begin
  if FData=AValue then exit;
  FData:=AValue;
  SetupMediators;
end;

procedure TCityEditForm.SetupMediators;
begin
  if not Assigned(FMediator) then
  begin
    FMediator := TtiModelMediator.Create(self);
    FMediator.AddProperty('Name', edName);
    FMediator.AddProperty('ZIP', edZIP);
    FMediator.AddProperty('Country', cbCountry).ValueList := gContactManager.CountryList;
  end;
  FMediator.Subject := FData;
  FMediator.Active := True;
end;

procedure TCityEditForm.btnDebugClicked(Sender: TObject);
begin
  tiShowString(FData.AsDebugString);
end;

procedure TCityEditForm.AfterCreate;
begin
  {@VFD_BODY_BEGIN: CityEditForm}
  Name := 'CityEditForm';
  SetPosition(673, 204, 350, 186);
  WindowTitle := 'City Maintenance';

  lblName1 := TfpgLabel.Create(self);
  with lblName1 do
  begin
    Name := 'lblName1';
    SetPosition(8, 8, 80, 16);
    FontDesc := '#Label1';
    Hint := '';
    Text := 'City name:';
  end;

  edName := TfpgEdit.Create(self);
  with edName do
  begin
    Name := 'edName';
    SetPosition(8, 24, 200, 22);
    TabOrder := 1;
    Text := '';
    FontDesc := '#Edit1';
  end;

  lblName2 := TfpgLabel.Create(self);
  with lblName2 do
  begin
    Name := 'lblName2';
    SetPosition(8, 52, 80, 16);
    FontDesc := '#Label1';
    Hint := '';
    Text := 'ZIP code:';
  end;

  edZIP := TfpgEdit.Create(self);
  with edZIP do
  begin
    Name := 'edZIP';
    SetPosition(8, 68, 120, 22);
    TabOrder := 3;
    Text := '';
    FontDesc := '#Edit1';
  end;

  lblName3 := TfpgLabel.Create(self);
  with lblName3 do
  begin
    Name := 'lblName3';
    SetPosition(8, 96, 80, 16);
    FontDesc := '#Label1';
    Hint := '';
    Text := 'Country:';
  end;

  cbCountry := TfpgComboBox.Create(self);
  with cbCountry do
  begin
    Name := 'cbCountry';
    SetPosition(8, 112, 200, 22);
    FontDesc := '#List';
    TabOrder := 5;
  end;

  btnSave := TfpgButton.Create(self);
  with btnSave do
  begin
    Name := 'btnSave';
    SetPosition(182, 156, 80, 24);
    Anchors := [anRight,anBottom];
    Text := 'Save';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 6;
    ModalResult := mrOK;
  end;

  btnCancel := TfpgButton.Create(self);
  with btnCancel do
  begin
    Name := 'btnCancel';
    SetPosition(266, 156, 80, 24);
    Anchors := [anRight,anBottom];
    Text := 'Cancel';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 7;
    ModalResult := mrCancel;
  end;

  btnDebug := TfpgButton.Create(self);
  with btnDebug do
  begin
    Name := 'btnDebug';
    SetPosition(8, 156, 100, 24);
    Text := 'Debug (Show)';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 8;
    OnClick := @btnDebugClicked;
  end;

  {@VFD_BODY_END: CityEditForm}
end;


end.