Search code examples
delphidelphi-xe5rtti

rtti dont call the wanted overloaded function when default values are used


I have an issue in a rtti method call resolution. my rtti resolve code is the one implemented as solution in the following topic in this answer the author is using argument length as decisive comparator to select the overloaded method , BUT in my case I WANT TO use overloaded method using some default values which will not be resolved when facing the following :

first model (called) : User

contains as public :

         procedure OnMyFocusChanged(); overload;
         procedure OnMyFocusChanged(Caller : Integer ; id : Integer = -1); overload;

second model : User_block.pas

have this line : CTRL.Start('User','OnMyFocusChanged',[index]); CTRL is a controller that contains some methods that works 100%, it will call the implemented method in the mentioned topic.

In the following case asking Rtti to resolve OnMyFocusChanged(index) will not be resolved.

Is there a way to fix this ?


Solution

  • I don't think that default parameter values are exposed by RTTI.

    In any case the cleanest solution is to stop using default arguments. Add a third overload that takes a single parameter. Implement it by calling the two parameter overload passing -1.