Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting property value by name

In a Delphi class I have some properties that I would like to set by accessing them by their name. Now I use e.g. Settings.AllowSysop := True;

That I would like to do something like Settings('AllowSysop').Value := True;

The reason for this is that when setting what my users can access this is read from a license file where the line read from the file (it is like an INI but encrypted) might look like

AllowSysop = True

I know it is some RTTI look-a-like code that has to be made but I can't quite figure it out.

I think it would make it a bit easier for me if this was possible.

Hope the explanation is making sense

like image 866
OZ8HP Avatar asked Jan 16 '13 06:01

OZ8HP


1 Answers

implementation
uses TypInfo;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
   if IsPublishedProp (Button1, 'Visible') then
    begin
      SetPropValue (Button1, 'Visible',false);
    end;

end;
like image 170
bummi Avatar answered Sep 27 '22 20:09

bummi