@@ -167,43 +167,47 @@ procedure TSQLiteConfig.LoadForm(aForm: TForm);
167167 { $ENDIF}
168168 I: Integer;
169169 JSONTela, JSONItem: TJSONObject;
170+ component: TComponent;
170171begin
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;
223228begin
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