1

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 ?

Community
  • 1
  • 1
  • There is no overloading here. You have two non-overloaded methods with the same name. Perhaps you can get these facts straight before we dive in. – David Heffernan May 17 '16 at 15:22
  • Regarding default parameters, I'd expect there to be nothing in the RTTI to reflect the default value. My expectation is that the early stages of the compiler transform the code at the call site to supply the default values, and then the latter stages of the compiler see the full argument list. – David Heffernan May 17 '16 at 15:25
  • @DavidHeffernan I m sorry is only a writing fault i really used this on a real code but unfortunately i m not allowed to share it . –  May 17 '16 at 16:08
  • 1
    The code in your edit does not compile. You still have no overloaded methods. Even if you overloaded it would not compile because the parameter lists are identical. You need to work much much harder in explaining your problem. Writing down made up code that does not represent your problem is pointless. We will close such questions. What you need to do is make a [mcve] so that we have some chance of understanding the actual problem. – David Heffernan May 17 '16 at 16:13
  • 1
    This question is not answerable. (This code that I wrote that I can't show you doesn't work?) – Warren P May 17 '16 at 16:37
  • I hope that will help !! @DavidHeffernan –  May 17 '16 at 16:54
  • Now read my second comment above. Have you evidence that rtti exposes default param values? I have none. Simple solution is to stop using defaults and add a third overload. – David Heffernan May 17 '16 at 17:06
  • thank you i used translator and understand now what you mean, is there a way to get the param properties of current function pointed by rtti , if it is possible ? –  May 17 '16 at 17:13
  • The code at the answer at the question you linked does exactly that. Without offering defaults. Why not do it the way I say. It is better anyway. – David Heffernan May 17 '16 at 17:17

1 Answers1

2

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I did as you commended me, but in order to satisfy my curiosity I asked my developement teammates and we got this as searching answer that I would share with you : [link](http://hallvards.blogspot.com/2006/05/hack-10-getting-parameters-of.html) –  May 17 '16 at 19:55