The good (and bad) old Delphi taught us the "classic" way of building application because of the way we write code "behind" the IDE.
Based on this paradigm, I built some time ago a library that allows me to save/load the GUI to INI file with a single line of code.
BAM! That's it! No more INI files!
The library only saves "relevant" properties. For example, for a
TCheckBox it saves only its
Checked property not also its
Top/Left. But it is more than enough.
Saving the form has no issues. However, I have "problems" during app initialization. They are not quite problems, but the initialization code is not that nice/elegant.
For example when I assign
Checkbox1.Checked := True it will trigger the
OnClick event (supposing that the checkbox was unchecked at design time). But assigning a
False value (naturally) will not trigger the
Therefore, I have to manually call
SaveForm(FormName) to make sure that whatever code is in
CheckBox1Click, it gets initialized. But this raises another problem. The
CheckBox1Click(Sender) might be called twice during application start up (once by
SaveForm and once my me, manually).
Of course, in theory the logic of the program should be put in individual objects and separated from the GUI. But even if we do this, the initialization problem remains. You load the properties of the object from disk and you assign them to the GUI. When you set whatever value you have in your object to
Checkbox1, it will (or not) call
CheckBox1Click(Sender) which will set the value back into the object.
On app startup:
procedure TForm.FormCreate (Sender: TObject);
LogicObject.Load(File); // load app logic
Checkbox1.Checked := LogicObject.Checked; // assign object to GUI
procedure TForm.CheckBox1Click(Sender: TObject);
LogicObject.Checked := Checkbox1.Checked;
Probably the solution involves writing stuff like this for EVERY control on the form:
OldEvent := CheckBox1.OnClick;
CheckBox1.OnClick := Nil;
CheckBox1.Checked := something;
CheckBox1.OnClick := OldEvent;
How do you solve this specific problem OR what is your approach when saving/restoring your GUI to/from disk?