I will answer this question myself, but feel free to provide your answers if you are faster than me or if you don't like my solution. I just came up with this idea and would like to have some opinions on that.
Goal: a configuration class that is readable (like an INI-file) but without having to write (and adapt after a new configuration item has been added) the load and save methods.
I want to create a class like
TMyConfiguration = class (TConfiguration)
...
property ShowFlags : Boolean read FShowFlags write FShowFlags;
property NumFlags : Integer read FNumFlags write FNumFlags;
end;
Calling TMyConfiguration.Save (inherited from TConfiguration) should create a file like
[Options]
ShowFlags=1
NumFlags=42
Question: What is the best way to do this?
Best Answer
This is my proposed solution.
I have a base class
The Load methods look like this (Save method accordingly):
The base class could provide load and save methods for the delphi default types. I can then create a configuration for my application like this:
Example of a custom save method: