I have a few different classes which origin is a another class. I have one property that is extended to all other classes.
But different classes handle this property differently.
So i want to do this:
TClass(ObjectPointer).Property:=Value;
But TClass is unknown class type
Can i do something like that:
ObjectPointer.ClassType(ObjectPointer).Property:=Value
or this
var
ClassRef: TClass;
begin
ClassRef := Sender.ClassType;
ClassRef(ObjectPointer).DoStuff
end;
Is there way to do this in delphi without using if statement
Please note, the code from this post will work only for published properties!
To answer your question if there’s a way to set a property value without using if statement, check the following overloaded functions.
The first one is for char, string, variant, integer, 64-bit integer, float, enumeration, set and dynamic array type of properties (phew). The second one is just for class type properties. Both will return True if given property exists and the value or object instance is successfuly assigned, False otherwise:
And the usage; when the
Memo1.Linesis set the, the second version ofTrySetPropValueis called: