Skip to content

Commit 9bc29d6

Browse files
committed
+ Função ClearDataBase em config.
1 parent daf05c7 commit 9bc29d6

4 files changed

Lines changed: 85 additions & 29 deletions

File tree

config/delphi/Config.SQLite.FireDAC.pas

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ TSQLiteConfig = class
4848
procedure SaveForm(aForm: TForm);
4949
procedure LoadForm(aForm: TForm);
5050
function ValidaBanco: boolean;
51+
procedure ClearDatabase;
5152
end;
5253

5354
var
@@ -56,6 +57,13 @@ TSQLiteConfig = class
5657
implementation
5758

5859
{ TSQLiteConfig }
60+
61+
procedure TSQLiteConfig.ClearDatabase;
62+
begin
63+
FDataSet.ExecSQL('DROP TABLE IF EXISTS Config');
64+
Validate;
65+
end;
66+
5967
constructor TSQLiteConfig.Create(aFileName: string = 'config.db');
6068
begin
6169
{$IFDEF MSWINDOWS} // android já possui a dll instalada
@@ -181,36 +189,45 @@ procedure TSQLiteConfig.LoadForm(aForm: TForm);
181189
try
182190
for I := 0 to pred(aForm.ComponentCount) do
183191
begin
184-
component := aForm.Components[I];
192+
component := aForm.Components[I];
185193
if JSONTela.getValue(component.Name) <> nil then
186-
if (component.Name <> EmptyStr) and (component.Tag <> -1) then
187-
if (component is TEdit) then
188-
TEdit(component).Text := JSONTela.getValue(TEdit(component).Name).Value
189-
else if (component is TComboBox) then
190-
TComboBox(component).ItemIndex := JSONTela.getValue(TComboBox(component).Name).Value.ToInteger
194+
if (component.Name <> EmptyStr) and (component.Tag <> -1) then
195+
if (component is TEdit) then
196+
TEdit(component).Text :=
197+
JSONTela.getValue(TEdit(component).Name).Value
198+
else if (component is TComboBox) then
199+
TComboBox(component).ItemIndex :=
200+
JSONTela.getValue(TComboBox(component).Name).Value.ToInteger
191201
{$IFDEF HAS_FMX}
192-
else if (component is TComboEdit) then
193-
TComboEdit(component).ItemIndex := JSONTela.getValue(TComboEdit(component).Name).Value.ToInteger
194-
else if (component is TDateEdit) then
195-
TDateEdit(component).Text := JSONTela.getValue(TDateEdit(component).Name).Value
196-
else if (component is TSwitch) then
197-
TSwitch(component).IsChecked := JSONTela.getValue(TSwitch(component).Name).Value.ToBoolean
202+
else if (component is TComboEdit) then
203+
TComboEdit(component).ItemIndex :=
204+
JSONTela.getValue(TComboEdit(component).Name).Value.ToInteger
205+
else if (component is TDateEdit) then
206+
TDateEdit(component).Text :=
207+
JSONTela.getValue(TDateEdit(component).Name).Value
208+
else if (component is TSwitch) then
209+
TSwitch(component).IsChecked :=
210+
JSONTela.getValue(TSwitch(component).Name).Value.ToBoolean
198211
{$ENDIF}
199-
else if (component is TCheckBox) then
200-
TCheckBox(component).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF} := JSONTela.GetValue(TCheckBox(component).Name).Value.ToBoolean
212+
else if (component is TCheckBox) then
213+
TCheckBox(component).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF} := JSONTela.getValue(TCheckBox(component).Name).Value.ToBoolean
201214
{$IFNDEF HAS_FMX}
202-
else if component is TLabeledEdit then
203-
TLabeledEdit(component).Text := JSONTela.getValue(TLabeledEdit(component).Name).Value
204-
else if (component is TValueListEditor) then
205-
begin
206-
JSONItem := TJSONObject(TJSONObject.ParseJSONValue(JSONTela.getValue(TValueListEditor(component).Name).ToJSON));
207-
if JSONItem <> nil then
208-
for J := 1 to pred(TValueListEditor(component).RowCount) do
209-
TValueListEditor(component).Cells[1, J] := JSONItem.getValue(TValueListEditor(component).Keys[J]).Value;
210-
JSONItem.Free;
211-
end
215+
else if component is TLabeledEdit then
216+
TLabeledEdit(component).Text :=
217+
JSONTela.getValue(TLabeledEdit(component).Name).Value
218+
else if (component is TValueListEditor) then
219+
begin
220+
JSONItem :=
221+
TJSONObject(TJSONObject.ParseJSONValue
222+
(JSONTela.getValue(TValueListEditor(component).Name).ToJSON));
223+
if JSONItem <> nil then
224+
for J := 1 to pred(TValueListEditor(component).RowCount) do
225+
TValueListEditor(component).Cells[1, J] :=
226+
JSONItem.getValue(TValueListEditor(component).Keys[J]).Value;
227+
JSONItem.Free;
228+
end
212229
{$ENDIF}
213-
;
230+
;
214231
end;
215232
finally
216233
JSONTela.Free;
@@ -244,16 +261,19 @@ procedure TSQLiteConfig.SaveForm(aForm: TForm);
244261
JSONTela.AddPair(TSwitch(component).Name, TSwitch(component).IsChecked)
245262
{$ENDIF}
246263
else if component is TCheckBox then
247-
JSONTela.AddPair(TCheckBox(component).Name, TCheckBox(component).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF})
264+
JSONTela.AddPair(TCheckBox(component).Name,
265+
TCheckBox(component).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF})
248266
{$IFNDEF HAS_FMX}
249267
else if component is TLabeledEdit then
250268
JSONTela.AddPair(TLabeledEdit(component).Name, TLabeledEdit(component).Text)
251269
else if component is TValueListEditor then
252270
begin
253271
JSONItem := TJSONObject.Create;
254272
for J := 1 to pred(TValueListEditor(component).RowCount) do
255-
JSONItem.AddPair(TValueListEditor(component).Keys[J], TValueListEditor(component).Cells[1, J]);
256-
JSONTela.AddPair(TValueListEditor(component).Name, TJSONObject.ParseJSONValue(JSONItem.ToJSON));
273+
JSONItem.AddPair(TValueListEditor(component).Keys[J],
274+
TValueListEditor(component).Cells[1, J]);
275+
JSONTela.AddPair(TValueListEditor(component).Name,
276+
TJSONObject.ParseJSONValue(JSONItem.ToJSON));
257277
JSONItem.Free;
258278
end
259279
{$ENDIF}

config/delphi/Config.SQLite.Zeos.pas

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TSQLiteConfig = class
3333
FDataSet: TZQuery;
3434
function Validate: boolean;
3535
function GetDefaultDir(aFileName: string): string;
36-
function isJSON(aJSON: string): boolean;
36+
function isJSON(aJSON: string): boolean;
3737
public
3838
constructor Create(aFileName: string = 'config.db');
3939
destructor Destroy; override;
@@ -44,12 +44,24 @@ TSQLiteConfig = class
4444
procedure SaveForm(aForm: TForm);
4545
procedure LoadForm(aForm: TForm);
4646
function ValidaBanco: boolean;
47+
procedure ClearDatabase;
4748
end;
4849

4950
implementation
5051

5152
{ TSQLiteConfig }
5253

54+
procedure TSQLiteConfig.ClearDatabase;
55+
begin
56+
with FDataSet do
57+
begin
58+
SQL.Clear;
59+
SQL.Add('DROP TABLE IF EXISTS Config');
60+
ExecSQL;
61+
end;
62+
Validate;
63+
end;
64+
5365
constructor TSQLiteConfig.Create(aFileName: string = 'config.db');
5466
begin
5567
FConn := TZConnection.Create(nil);

config/lazarus/config.sqlite.sqldb.pas

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,24 @@ TSQLiteConfig = class
3333
procedure SaveForm(aForm: TForm);
3434
procedure LoadForm(aForm: TForm);
3535
function ValidaBanco: boolean;
36+
procedure ClearDatabase;
3637
end;
3738

3839
implementation
3940

4041
{ TSQLiteConfig }
4142

43+
procedure TSQLiteConfig.ClearDatabase;
44+
begin
45+
with FDataSet do
46+
begin
47+
SQL.Clear;
48+
SQL.Add('DROP TABLE IF EXISTS Config');
49+
ExecSQL;
50+
end;
51+
Validate;
52+
end;
53+
4254
constructor TSQLiteConfig.Create(aFileName: string);
4355
begin
4456
FConn := TSQLConnector.Create(nil);

config/lazarus/config.sqlite.zeos.pas

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,24 @@ TSQLiteConfig = class
3131
procedure SaveForm(aForm: TForm);
3232
procedure LoadForm(aForm: TForm);
3333
function ValidaBanco: boolean;
34+
procedure ClearDataBase;
3435
end;
3536

3637
implementation
3738

3839
{ TSQLiteConfig }
3940

41+
procedure TSQLiteConfig.ClearDatabase;
42+
begin
43+
with FDataSet do
44+
begin
45+
SQL.Clear;
46+
SQL.Add('DROP TABLE IF EXISTS Config');
47+
ExecSQL;
48+
end;
49+
Validate;
50+
end;
51+
4052
constructor TSQLiteConfig.Create(aFileName: string);
4153
begin
4254
FConn := TZConnection.Create(nil);

0 commit comments

Comments
 (0)