Skip to content

Commit 6ff4fe1

Browse files
committed
- Correção de Typecast FireDAC
* Adição de recurso de ignorar campos com tag = -1
1 parent d81f3ad commit 6ff4fe1

2 files changed

Lines changed: 103 additions & 88 deletions

File tree

config/delphi/Config.SQLite.FireDAC.pas

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -175,39 +175,43 @@ procedure TSQLiteConfig.LoadForm(aForm: TForm);
175175
{$ENDIF}
176176
I: Integer;
177177
JSONTela, JSONItem: TJSONObject;
178+
component: TComponent;
178179
begin
179180
JSONTela := LoadConfig;
180181
try
181182
for I := 0 to pred(aForm.ComponentCount) do
182-
if JSONTela.getValue(aForm.Components[I].Name) <> nil then
183-
if (aForm.Components[I] is TEdit) then
184-
TEdit(aForm.Components[I]).Text := JSONTela.getValue(TEdit(aForm.Components[I]).Name).Value
185-
else if (aForm.Components[I] is TComboBox) then
186-
TComboBox(aForm.Components[I]).ItemIndex := JSONTela.getValue(TEdit(aForm.Components[I]).Name).Value.ToInteger
183+
begin
184+
component := aForm.Components[I];
185+
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
187191
{$IFDEF HAS_FMX}
188-
else if (aForm.Components[I] is TComboEdit) then
189-
TComboEdit(aForm.Components[I]).ItemIndex := JSONTela.getValue(TEdit(aForm.Components[I]).Name).Value.ToInteger
190-
else if (aForm.Components[I] is TDateEdit) then
191-
TDateEdit(aForm.Components[I]).Text := JSONTela.getValue(TEdit(aForm.Components[I]).Name).Value
192-
else if (aForm.Components[I] is TSwitch) then
193-
TSwitch(aForm.Components[I]).IsChecked := JSONTela.getValue(TEdit(aForm.Components[I]).Name).Value.ToBoolean
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
194198
{$ENDIF}
195-
else if (aForm.Components[I] is TCheckBox) then
196-
TCheckBox(aForm.Components[I]).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF} := JSONTela.Get(TEdit(aForm.Components[I]).Name)
197-
.Value.ToBoolean
199+
else if (component is TCheckBox) then
200+
TCheckBox(component).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF} := JSONTela.GetValue(TCheckBox(component).Name).Value.ToBoolean
198201
{$IFNDEF HAS_FMX}
199-
else if aForm.Components[I] is TLabeledEdit then
200-
TLabeledEdit(aForm.Components[I]).Text := JSONTela.getValue(TLabeledEdit(aForm.Components[I]).Name).Value
201-
else if (aForm.Components[I] is TValueListEditor) then
202+
else if component is TLabeledEdit then
203+
TLabeledEdit(component).Text := JSONTela.getValue(TLabeledEdit(component).Name).Value
204+
else if (component is TValueListEditor) then
202205
begin
203-
JSONItem := TJSONObject(TJSONObject.ParseJSONValue(JSONTela.getValue(TValueListEditor(aForm.Components[I]).Name).ToJSON));
206+
JSONItem := TJSONObject(TJSONObject.ParseJSONValue(JSONTela.getValue(TValueListEditor(component).Name).ToJSON));
204207
if JSONItem <> nil then
205-
for J := 1 to pred(TValueListEditor(aForm.Components[I]).RowCount) do
206-
TValueListEditor(aForm.Components[I]).Cells[1, J] := JSONItem.getValue(TValueListEditor(aForm.Components[I]).Keys[J]).Value;
208+
for J := 1 to pred(TValueListEditor(component).RowCount) do
209+
TValueListEditor(component).Cells[1, J] := JSONItem.getValue(TValueListEditor(component).Keys[J]).Value;
207210
JSONItem.Free;
208211
end
209212
{$ENDIF}
210213
;
214+
end;
211215
finally
212216
JSONTela.Free;
213217
end;
@@ -220,37 +224,41 @@ procedure TSQLiteConfig.SaveForm(aForm: TForm);
220224
{$ENDIF}
221225
I: Integer;
222226
JSONTela, JSONItem: TJSONObject;
227+
component: TComponent;
223228
begin
224229
JSONTela := TJSONObject.Create;
225230
try
226231
for I := 0 to pred(aForm.ComponentCount) do
227-
if aForm.Components[I] is TEdit then
228-
JSONTela.AddPair(TEdit(aForm.Components[I]).Name, TEdit(aForm.Components[I]).Text)
229-
else if aForm.Components[I] is TComboBox then
230-
JSONTela.AddPair(TComboBox(aForm.Components[I]).Name, TComboBox(aForm.Components[I]).ItemIndex)
232+
begin
233+
component := aForm.Components[I];
234+
if component is TEdit then
235+
JSONTela.AddPair(TEdit(component).Name, TEdit(component).Text)
236+
else if component is TComboBox then
237+
JSONTela.AddPair(TComboBox(component).Name, TComboBox(component).ItemIndex)
231238
{$IFDEF HAS_FMX}
232-
else if aForm.Components[I] is TComboEdit then
233-
JSONTela.AddPair(TComboEdit(aForm.Components[I]).Name, TComboEdit(aForm.Components[I]).ItemIndex)
234-
else if aForm.Components[I] is TDateEdit then
235-
JSONTela.AddPair(TDateEdit(aForm.Components[I]).Name, TDateEdit(aForm.Components[I]).Text)
236-
else if aForm.Components[I] is TSwitch then
237-
JSONTela.AddPair(TSwitch(aForm.Components[I]).Name, TSwitch(aForm.Components[I]).IsChecked)
239+
else if component is TComboEdit then
240+
JSONTela.AddPair(TComboEdit(component).Name, TComboEdit(component).ItemIndex)
241+
else if component is TDateEdit then
242+
JSONTela.AddPair(TDateEdit(component).Name, TDateEdit(component).Text)
243+
else if component is TSwitch then
244+
JSONTela.AddPair(TSwitch(component).Name, TSwitch(component).IsChecked)
238245
{$ENDIF}
239-
else if aForm.Components[I] is TCheckBox then
240-
JSONTela.AddPair(TCheckBox(aForm.Components[I]).Name, TCheckBox(aForm.Components[I]).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF})
246+
else if component is TCheckBox then
247+
JSONTela.AddPair(TCheckBox(component).Name, TCheckBox(component).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF})
241248
{$IFNDEF HAS_FMX}
242-
else if aForm.Components[I] is TLabeledEdit then
243-
JSONTela.AddPair(TLabeledEdit(aForm.Components[I]).Name, TLabeledEdit(aForm.Components[I]).Text)
244-
else if aForm.Components[I] is TValueListEditor then
249+
else if component is TLabeledEdit then
250+
JSONTela.AddPair(TLabeledEdit(component).Name, TLabeledEdit(component).Text)
251+
else if component is TValueListEditor then
245252
begin
246253
JSONItem := TJSONObject.Create;
247-
for J := 1 to pred(TValueListEditor(aForm.Components[I]).RowCount) do
248-
JSONItem.AddPair(TValueListEditor(aForm.Components[I]).Keys[J], TValueListEditor(aForm.Components[I]).Cells[1, J]);
249-
JSONTela.AddPair(TValueListEditor(aForm.Components[I]).Name, TJSONObject.ParseJSONValue(JSONItem.ToJSON));
254+
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));
250257
JSONItem.Free;
251258
end
252259
{$ENDIF}
253260
;
261+
end;
254262
UpdateConfig(JSONTela);
255263
finally
256264
JSONTela.Free;

config/delphi/Config.SQLite.Zeos.pas

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -167,43 +167,47 @@ procedure TSQLiteConfig.LoadForm(aForm: TForm);
167167
{$ENDIF}
168168
I: Integer;
169169
JSONTela, JSONItem: TJSONObject;
170+
component: TComponent;
170171
begin
171172
JSONTela := LoadConfig;
172173
try
173174
for I := 0 to pred(aForm.ComponentCount) do
174-
if JSONTela.getValue(aForm.Components[I].Name) <> nil then
175-
if (aForm.Components[I] is TEdit) then
176-
TEdit(aForm.Components[I]).Text :=
177-
JSONTela.getValue(TEdit(aForm.Components[I]).Name).Value
178-
else if (aForm.Components[I] is TComboBox) then
179-
TComboBox(aForm.Components[I]).ItemIndex :=
180-
JSONTela.getValue(TComboBox(aForm.Components[I]).Name).Value.ToInteger
175+
begin
176+
component := aForm.Components[I];
177+
if JSONTela.getValue(component.Name) <> nil then
178+
if (component.Name <> EmptyStr) and (component.Tag <> -1) then
179+
if (component is TEdit) then
180+
TEdit(component).Text :=
181+
JSONTela.getValue(TEdit(component).Name).Value
182+
else if (component is TComboBox) then
183+
TComboBox(component).ItemIndex :=
184+
JSONTela.getValue(TComboBox(component).Name).Value.ToInteger
181185
{$IFDEF HAS_FMX}
182-
else if (aForm.Components[I] is TComboEdit) then
183-
TComboEdit(aForm.Components[I]).ItemIndex :=
184-
JSONTela.getValue(TComboEdit(aForm.Components[I]).Name).Value.ToInteger
185-
else if (aForm.Components[I] is TDateEdit) then
186-
TDateEdit(aForm.Components[I]).Text :=
187-
JSONTela.getValue(TDateEdit(aForm.Components[I]).Name).Value
188-
else if (aForm.Components[I] is TSwitch) then
189-
TSwitch(aForm.Components[I]).IsChecked :=
190-
JSONTela.getValue(TSwitch(aForm.Components[I]).Name).Value.ToBoolean
186+
else if (component is TComboEdit) then
187+
TComboEdit(component).ItemIndex :=
188+
JSONTela.getValue(TComboEdit(component).Name).Value.ToInteger
189+
else if (component is TDateEdit) then
190+
TDateEdit(component).Text :=
191+
JSONTela.getValue(TDateEdit(component).Name).Value
192+
else if (component is TSwitch) then
193+
TSwitch(component).IsChecked :=
194+
JSONTela.getValue(TSwitch(component).Name).Value.ToBoolean
191195
{$ENDIF}
192-
else if (aForm.Components[I] is TCheckBox) then
193-
TCheckBox(aForm.Components[I]).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF} := JSONTela.Get(TCheckBox(aForm.Components[I]).Name).Value.ToBoolean
196+
else if (component is TCheckBox) then
197+
TCheckBox(component).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF} := JSONTela.GetValue(TCheckBox(component).Name).Value.ToBoolean
194198
{$IFNDEF HAS_FMX}
195-
else if aForm.Components[I] is TLabeledEdit then
199+
else if component is TLabeledEdit then
196200
TLabeledEdit(aForm.Components[I]).Text :=
197-
JSONTela.getValue(TLabeledEdit(aForm.Components[I]).Name).Value
198-
else if (aForm.Components[I] is TValueListEditor) then
201+
JSONTela.getValue(TLabeledEdit(component).Name).Value
202+
else if (component is TValueListEditor) then
199203
begin
200204
JSONItem :=
201205
TJSONObject(TJSONObject.ParseJSONValue
202-
(JSONTela.getValue(TValueListEditor(aForm.Components[I]).Name).ToJSON));
206+
(JSONTela.getValue(TValueListEditor(component).Name).ToJSON));
203207
if JSONItem <> nil then
204-
for J := 1 to pred(TValueListEditor(aForm.Components[I]).RowCount) do
205-
TValueListEditor(aForm.Components[I]).Cells[1, J] :=
206-
JSONItem.getValue(TValueListEditor(aForm.Components[I]).Keys[J]).Value;
208+
for J := 1 to pred(TValueListEditor(component).RowCount) do
209+
TValueListEditor(component).Cells[1, J] :=
210+
JSONItem.getValue(TValueListEditor(component).Keys[J]).Value;
207211
JSONItem.Free;
208212
end
209213
{$ENDIF}
@@ -220,46 +224,49 @@ procedure TSQLiteConfig.SaveForm(aForm: TForm);
220224
{$ENDIF}
221225
I: Integer;
222226
JSONTela, JSONItem: TJSONObject;
227+
component: TComponent;
223228
begin
224229
JSONTela := TJSONObject.Create;
225230
try
226231
for I := 0 to pred(aForm.ComponentCount) do
227-
if aForm.Components[I] is TEdit then
228-
JSONTela.AddPair(TEdit(aForm.Components[I]).Name, TEdit(aForm.Components[I]).Text)
229-
else if aForm.Components[I] is TComboBox then
230-
JSONTela.AddPair(TComboBox(aForm.Components[I]).Name,
231-
TComboBox(aForm.Components[I]).ItemIndex)
232+
begin
233+
component := aForm.Components[I]
234+
if component is TEdit then
235+
JSONTela.AddPair(TEdit(component).Name, TEdit(component).Text)
236+
else if component is TComboBox then
237+
JSONTela.AddPair(TComboBox(component).Name,
238+
TComboBox(component).ItemIndex)
232239
{$IFDEF HAS_FMX}
233-
else if aForm.Components[I] is TComboEdit then
234-
JSONTela.AddPair(TComboEdit(aForm.Components[I]).Name,
235-
TComboEdit(aForm.Components[I]).ItemIndex)
236-
else if aForm.Components[I] is TDateEdit then
237-
JSONTela.AddPair(TDateEdit(aForm.Components[I]).Name,
238-
TDateEdit(aForm.Components[I]).Text)
239-
else if aForm.Components[I] is TSwitch then
240-
JSONTela.AddPair(TSwitch(aForm.Components[I]).Name, TSwitch(aForm.Components[I])
240+
else if component is TComboEdit then
241+
JSONTela.AddPair(TComboEdit(component).Name,
242+
TComboEdit(component).ItemIndex)
243+
else if component is TDateEdit then
244+
JSONTela.AddPair(TDateEdit(component).Name,
245+
TDateEdit(component).Text)
246+
else if component is TSwitch then
247+
JSONTela.AddPair(TSwitch(component).Name, TSwitch(component)
241248
.IsChecked)
242249
{$ENDIF}
243-
else if aForm.Components[I] is TCheckBox then
244-
JSONTela.AddPair(TCheckBox(aForm.Components[I]).Name,
245-
TCheckBox(aForm.Components[I]).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF})
250+
else if component is TCheckBox then
251+
JSONTela.AddPair(TCheckBox(component).Name,
252+
TCheckBox(component).{$IFDEF HAS_FMX}IsChecked{$ELSE}Checked{$ENDIF})
246253
{$IFNDEF HAS_FMX}
247-
else if aForm.Components[I] is TLabeledEdit then
248-
JSONTela.AddPair(TLabeledEdit(aForm.Components[I]).Name,
249-
TLabeledEdit(aForm.Components[I]).Text)
250-
else if aForm.Components[I] is TValueListEditor then
254+
else if component is TLabeledEdit then
255+
JSONTela.AddPair(TLabeledEdit(component).Name,
256+
TLabeledEdit(component).Text)
257+
else if component is TValueListEditor then
251258
begin
252259
JSONItem := TJSONObject.Create;
253-
for J := 1 to pred(TValueListEditor(aForm.Components[I]).RowCount) do
254-
JSONItem.AddPair(TValueListEditor(aForm.Components[I]).Keys[J],
255-
TValueListEditor(aForm.Components[I]).Cells[1, J]);
256-
JSONTela.AddPair(TValueListEditor(aForm.Components[I]).Name,
260+
for J := 1 to pred(TValueListEditor(component).RowCount) do
261+
JSONItem.AddPair(TValueListEditor(component).Keys[J],
262+
TValueListEditor(component).Cells[1, J]);
263+
JSONTela.AddPair(TValueListEditor(component).Name,
257264
TJSONObject.ParseJSONValue(JSONItem.ToJSON));
258265
JSONItem.Free;
259266
end
260267
{$ENDIF}
261268
;
262-
269+
end;
263270
UpdateConfig(JSONTela);
264271
finally
265272
JSONTela.Free;

0 commit comments

Comments
 (0)