Read c:\rad studio\9.0\source\rtl\common\System.Rtti.pas
procedure TRttiInstanceProperty.DoSetValue
The setter of the property may be
- a field (variable)
- a static procedure
- a virtual procedure (your case)
And those cases make PropInfo^.SetProc
have different semantics of its value.
Direct address only applies to static procedures. For virtual methods you add a VMT offset and take the code address from that memory cell, as specified in that code i mentioned (but would not quote for copyright reasons).
Or you just could use TRttiProperty.SetValue
and let Delphi do all those little under the hood details. See http://docwiki.embarcadero.com/Libraries/XE2/en/System.Rtti.TRttiProperty.SetValue
EDIT:
- the code removed - it did not worked verbatim and the topic starter provided working version.
- Regarding and I know I should use
Extended RTTI
instead ofclassic
one - that is questionable claim.Extended RTTI
is known to work noticeably slower than classic one. Dunno if someone did profiled it, but i suspect that is mostly due to the slow code ofTValue
. You can google and find that lot of people complained of slowTValue
implementation and provided alternative ones with fixed efficiency. However sinceExtended RTTI
only uses stockTValue
it cannot benefit from those implementations and remains slower than classic one.