delphi - Call a protected method (constructor) via RTTI -


am using xe-2.

is possible invoke protected method (constructor) using rtti?

i searched web did not find conclusive answer. understand prior xe published methods/properties available. have write access private fields, expecting able invoke protected methods.

the following code works long constructor public.

function getdefaultconstructor(arttitype: trttitype): trttimethod; var    method: trttimethod; begin    method in arttitype.getmethods('create')    begin       if (method.isconstructor) , (length(method.getparameters) = 0) , (method.parent = arttitype)          exit(method);    end;    result := nil; end; 

rtti information increases size of executable files. because of designers provided means developer specify how rtti information linked executable.

by default, no rtti protected methods linked. have specify want rtti added. example, program

{$apptype console}  uses   system.typinfo, system.rtti;  type   tmyclass = class   protected     constructor create;   end;  constructor tmyclass.create; begin end;  var   ctx: trtticontext;   method: trttimethod;  begin   method in ctx.gettype(tmyclass).getmethods     if method.visibility=mvprotected       writeln(method.name); end. 

produces no output. however, program

{$apptype console}  uses   system.typinfo, system.rtti;  type   {$rtti explicit methods([vcprotected])}   tmyclass = class   protected     constructor create;   end;  constructor tmyclass.create; begin end;  var   ctx: trtticontext;   method: trttimethod;  begin   method in ctx.gettype(tmyclass).getmethods     if method.visibility=mvprotected       writeln(method.name); end. 

outputs

 create 

for more information, refer these documentation topics:


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -