I'm building a small class I wnat to use to save session data for a couple of my programs I use frequently.
The goal of the class is to make easier store in a ini file data uswed by program to do specific job. To make it more clear: I have a program I use to make a backup of some project to a backup folder. Since I use for several project, I need the functionality to remember each project's settings (source folder, destination folder, if copy recursively and so on).
Since I have the same need in another program, I decided to develop a class or a component which make this easy: I want to pass a list of components properties:
with mgProgramDataManager1.PropertiesValues do
The SaveData procedure in the component is as folllows:
procedure TmgProgramDataManager.SaveData(AJobName: string);
FFileName := AddBackSlash(FFilePath) + 'jobs.ini';
FIni := TIniFile.Create(FFileName);
for I := 0 to FPropertiesValues.Count - 1 do
sl := SplitString(FPropertiesValues[I], '.');
Cmp := FOwner.FindComponent(sl);
PropInfo := GetPropInfo(Cmp.ClassInfo, sl);
FIni.WriteString(AJobName, Cmp.Name, GetPropValue(Cmp, PropInfo.Name));
But not all works fine: properties like Lines is stored as a number. So I think to have check if a property is of type TStrings and change the code accordingly, but I can't get rid of how I can do it.
I think to have to use RTTI, but I'm struggled trying to understand how to get the property type.
I also know about component streaming and I had yet built a working class, but I had two problems:
1) as it is, component streaming use default values, so if in a job a checkbox is checked and in another one the checkbox is not checked and I want to pas from the first job to the second one, all values are restored as they were, but the checkbox remains checked because saving the second job the unchecked state is not saved into the stream file (so it can't be restored)
2) I solved this problem checking by myself is a component is a TCheckBox or a TRadioButton but in this case the component will not be able to manage any descendant component (for instance TJvCheckBox)or it will have to create an if statement for any possible component like TCheckListBox an so on.
So the question is: how can I get the type of a property to know if it is TStrings? Or, alternatively, how can deal with this type of task?
Thanks in advance.