summaryrefslogtreecommitdiff
path: root/extras/tiopf/demos/Demo_04_CreateDatabase/frm_main.pas
blob: cee11cd07291dbf01e72c3ed7cf10e554493dd9e (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
unit frm_main;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_button, fpg_panel;

type

  TMainForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: MainForm}
    btnPickDB: TfpgButton;
    btnCreateDB: TfpgButton;
    btnDBExists: TfpgButton;
    pnlDBName: TfpgPanel;
    {@VFD_HEAD_END: MainForm}
    FPersistenceLayerName: string;
    FDatabaseName: string;
    FUsername: string;
    FPassword: string;
    procedure PickDBClicked(Sender: TObject);
    procedure DatabaseExistsClicked(Sender: TObject);
    procedure CreateDatabaseClicked(Sender: TObject);
  public
    procedure AfterCreate; override;
  end;

{@VFD_NEWFORM_DECL}

implementation

uses
  frm_pickdatabase
  ,fpg_dialogs
  ,tiOPFManager
  ,tiPersistenceLayers
  ,tiDialogs
  ;

{@VFD_NEWFORM_IMPL}

procedure TMainForm.PickDBClicked(Sender: TObject);
var
  frm: TPickDatabaseForm;
begin
  frm := TPickDatabaseForm.Create(nil);
  try
    if frm.ShowModal = mrOK then
    begin
      FPersistenceLayerName := frm.PersistenceLayerName;
      FDatabaseName := frm.DatabaseName;
      FUsername := frm.UserName;
      FPassword := frm.Password;
      pnlDBName.Text := frm.DatabaseName;
    end;
  finally
    frm.Free;
  end;
end;

procedure TMainForm.DatabaseExistsClicked(Sender: TObject);
var
  LPerLayer: TtiPersistenceLayer;
begin
  LPerLayer:= GTIOPFManager.PersistenceLayers.FindByPersistenceLayerName(FPersistenceLayerName);
  Assert(LPerLayer<>nil, '"' + FPersistenceLayerName + '" not registered');
  if LPerLayer.DatabaseExists(FDatabaseName, FUserName, FPassword)
  then
    tiAppMessage('Database <' + FDatabaseName + '> exists.')
  else
    tiAppWarning('Database <' + FDatabaseName + '> does not exist.');
end;

procedure TMainForm.CreateDatabaseClicked(Sender: TObject);
var
  LPerLayer: TtiPersistenceLayer;
begin
  LPerLayer:= GTIOPFManager.PersistenceLayers.FindByPersistenceLayerName(FPersistenceLayerName);
  Assert(LPerLayer<>nil, '"' + FPersistenceLayerName + '" not registered');
  LPerLayer.CreateDatabase(FDatabaseName, FUserName, FPassword);
  tiAppMessage('Database "' + FDatabaseName + '" has been created.');
end;

procedure TMainForm.AfterCreate;
begin
  {@VFD_BODY_BEGIN: MainForm}
  Name := 'MainForm';
  SetPosition(312, 189, 359, 182);
  WindowTitle := 'Demo 04 - Create Database';
  WindowPosition := wpScreenCenter;

  btnPickDB := TfpgButton.Create(self);
  with btnPickDB do
  begin
    Name := 'btnPickDB';
    SetPosition(108, 20, 144, 24);
    Text := 'Pick Database';
    AllowAllUp := False;
    Embedded := False;
    Flat := False;
    FontDesc := '#Label1';
    GroupIndex := 0;
    Hint := '';
    ImageLayout := ilImageLeft;
    ImageMargin := 3;
    ImageName := '';
    ImageSpacing := -1;
    ParentShowHint := True;
    ShowImage := True;
    TabOrder := 0;
    OnClick := @PickDBClicked;
  end;

  btnCreateDB := TfpgButton.Create(self);
  with btnCreateDB do
  begin
    Name := 'btnCreateDB';
    SetPosition(108, 96, 136, 24);
    Text := 'Create Database';
    AllowAllUp := False;
    Embedded := False;
    Flat := False;
    FontDesc := '#Label1';
    GroupIndex := 0;
    Hint := '';
    ImageLayout := ilImageLeft;
    ImageMargin := 3;
    ImageName := '';
    ImageSpacing := -1;
    ParentShowHint := True;
    ShowImage := True;
    TabOrder := 1;
    OnClick := @CreateDatabaseClicked;
  end;

  btnDBExists := TfpgButton.Create(self);
  with btnDBExists do
  begin
    Name := 'btnDBExists';
    SetPosition(108, 128, 136, 24);
    Text := 'Database Exists';
    AllowAllUp := False;
    Embedded := False;
    Flat := False;
    FontDesc := '#Label1';
    GroupIndex := 0;
    Hint := '';
    ImageLayout := ilImageLeft;
    ImageMargin := 3;
    ImageName := '';
    ImageSpacing := -1;
    ParentShowHint := True;
    ShowImage := True;
    TabOrder := 2;
    OnClick := @DatabaseExistsClicked;
  end;

  pnlDBName := TfpgPanel.Create(self);
  with pnlDBName do
  begin
    Name := 'pnlDBName';
    SetPosition(12, 56, 336, 32);
    Anchors := [anLeft,anRight,anTop];
    ParentShowHint := True;
    Style := bsLowered;
    Text := '---';
  end;

  {@VFD_BODY_END: MainForm}
end;


end.