How to get property property (Method: TRttiMethod) in TVirtualInterface TVirtualInterfaceInvokeEvent?

How to get the property of the method property: TRttiMethod in the OnInvoke method of the TVirtualInterface class?

I have this interface:

IPerson = interface(IInvokable) ['{45CE428C-F880-4D61-A2C1-0F3CB47130B5}'] procedure SetName(const Value: string); function GetName(): string; [TEntityField('Field Name Here')] property Name: string read GetName write SetName; end; 

and this class:

 type TVirtualEntity<T: IInvokable> = class(TVirtualInterface) public constructor Create(); reintroduce; overload; end; constructor TVirtualEntity<T>.Create; begin inherited Create(TypeInfo(T)); Self.OnInvoke := procedure(Method: TRttiMethod; const Args: TArray<TValue>; out Result: TValue) var attributes: TArray<TCustomAttribute>; attributesManager: TAttributesManager; entityFieldAttribute: TEntityField; begin attributesManager := TAttributesManager.Create(Method.GetAttributes); try if attributesManager.HasAttribute<TEntityField>() then begin Result := attributesManager.GetAttribute<TEntityField>.FieldName; end; finally attributesManager.Free; end; end; end; 

I would like to get the TRttiProperty method: TRttiMethod, but how? if I changed the interface to:

 IPerson = interface(IInvokable) ['{45CE428C-F880-4D61-A2C1-0F3CB47130B5}'] procedure SetName(const Value: string); [TEntityField('Field Name Here')] function GetName(): string; property Name: string read GetName write SetName; end; 

the code works, but I would like to use the following user interfaces:

 IPerson = interface(IInvokable) ['{45CE428C-F880-4D61-A2C1-0F3CB47130B5}'] procedure SetName(const Value: string); function GetName(): string; [TEntityField('Field Name Here')] property Name: string read GetName write SetName; end; 
+8
rtti delphi delphi-10.1-berlin
source share
1 answer

Sorry, you can’t. No RTTI is created for interface properties, so there is nothing for your custom attribute. Your decoration of an interface property has no effect, even if there are no warnings.

+6
source share

All Articles