@@ -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
5354var
@@ -56,6 +57,13 @@ TSQLiteConfig = class
5657implementation
5758
5859{ TSQLiteConfig }
60+
61+ procedure TSQLiteConfig.ClearDatabase ;
62+ begin
63+ FDataSet.ExecSQL(' DROP TABLE IF EXISTS Config' );
64+ Validate;
65+ end ;
66+
5967constructor TSQLiteConfig.Create(aFileName: string = ' config.db' );
6068begin
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}
0 commit comments