I have some object newObject
with unknown properties and I want to be able to assign values to its properties without knowing what type the property is.
The best I can do so far is
vCtx := TRttiContext.Create;
vType := vCtx.GetType(newObject.ClassType);
for vProp in vType.GetProperties do
begin
vPropValue := 'Test Value';
val := TValue.From<String>( vPropValue);
vProp.SetValue( newObject , val );
end;
Of course, this assumes that the properties are of type string
How do I make this more general?
Aucun commentaire:
Enregistrer un commentaire