I would like to use attributes to read/write in property values to/from the registry.
All of the examples I have looked use a Load/Save function to loop over all the properties and examine the attributes. Instead of having a Load/Save routine I would like to read the value from the registry when the property is read or written. However, I can't figure out how to find out the name of the current property in the Read method.
I know I could have a one line getter/setter for my properties that pass in the correct string values to the Read/Write methods. I was hoping I could use attributes. Then when I define simple classes with the properties I want to save and restore. I would not need to write have any code for those classes. Everything would be dealt with the in the base class.
It could be that this is not possible.
I'm taking this example from Robert Love as my starting point: http://robstechcorner.blogspot.de/2009/10/ini-persistence-rtti-way.html
type
RegValueAttribute = class(TCustomAttribute)
private
FName: string;
FDefaultValue: string;
published
constructor Create(const aName : string;const aDefaultValue : String = '');
property Name : string read FName write FName;
property DefaultValue : string read FDefaultValue write FDefaultValue;
end;
TRegBaseClass = class
protected
procedure WriteString(AValue: string);
function ReadString: string;
end;
TMyRegClass = class(TRegBaseClass)
public
[RegValueAttribute('MySavedProperty', 'DefaultValue')]
property MySavedProperty: string read ReadString write WriteString;
end;
///////////////////////////////////////////
function TRegBaseClass.ReadString: string;
begin
// ?? Is there any way to get the attributes for the property
// that got me here.
end;
procedure TRegBaseClass.ReadString(AValue: string);
begin
// ?? Is there any way to get the attributes for the property
// that got me here.
end;