luben111
Advanced Member level 1
Hi,
I have the following problem - to read and write the properties of components in my application. Imagine that I have a TLabel component and it has Property Font.Name
How I can access the property of Font.Name by using strings as description of the field names - i.e. I need a function like this
ReadComponentPropertyAsSTring(component : TComponent; propertyName : String) : String;
If the property is not nested (example for nested property is Label1.Font.Name) then I can easily read or write the property by using GetPropInfo, GetPropValue and SetPropValue as listed below:
function ReadComponentPropertyAsString(component : TComponent; propertyName : String) : String; // read the property of component
var
propInfo : PPropInfo;
begin
Result := '';
propInfo := GetPropInfo(component.ClassInfo, propertyName); // we try to locate the property from RTTI
if Assigned(propInfo) then
begin
Result := GetPropValue(component, PropInfo, True); // we'll get the property as string
end;
end;
My question is - how should look like the same function ReadComponentPropertyAsString listed above if I have to read the property of Label1.Font.Name ?
Thank you!
I have the following problem - to read and write the properties of components in my application. Imagine that I have a TLabel component and it has Property Font.Name
How I can access the property of Font.Name by using strings as description of the field names - i.e. I need a function like this
ReadComponentPropertyAsSTring(component : TComponent; propertyName : String) : String;
If the property is not nested (example for nested property is Label1.Font.Name) then I can easily read or write the property by using GetPropInfo, GetPropValue and SetPropValue as listed below:
function ReadComponentPropertyAsString(component : TComponent; propertyName : String) : String; // read the property of component
var
propInfo : PPropInfo;
begin
Result := '';
propInfo := GetPropInfo(component.ClassInfo, propertyName); // we try to locate the property from RTTI
if Assigned(propInfo) then
begin
Result := GetPropValue(component, PropInfo, True); // we'll get the property as string
end;
end;
My question is - how should look like the same function ReadComponentPropertyAsString listed above if I have to read the property of Label1.Font.Name ?
Thank you!