2.6a vs 2.8 Method or procedure calls. Error or behavior change?

We encourage new members to introduce themselves here. Get to know one another and share your interests.
Post Reply
jpmoschi
Posts: 77
Joined: Thu May 21, 2020 3:45 pm

2.6a vs 2.8 Method or procedure calls. Error or behavior change?

Post by jpmoschi »

I have declared a method in a class

Code: Select all

public method say(fila as usual, columna as usual, ptext as usual, ppicture as usual, flgbold as usual, flgunderline as usual, flgreverse as usual) as void

in 2.6a i can call them with less parameters like this

Code: Select all

   oFormTest:Say(0,0,"Start  the Dbase III Plus look Test inputting a quantity of iterations ")
in 2.8 this line produce an error and the solution was to put all the declared arguments. Is it necesary? Is it an error?

Code: Select all

   oFormTest:Say(0,0,"Start  the Dbase III Plus look Test inputting a quantity of iterations ",,,, )
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

2.6a vs 2.8 Method or procedure calls. Error or behavior change?

Post by robert »

Juan Pablo,
How did you declare oFormTest ? And did you change that ?

I guess that before you did not declare it as a specific type and now you declared it with a type.

The difference is that without a specific type this was compiled into a "Late Bound" method call. The compiler then generates a call to a function in the runtime (Send) and this Send() function at runtime uses reflection to figure out what the right number of parameters is that the Say() method wants to have and will add default values for the missing arguments.

If you declare the local variable as your type (MyForm) then the compiler checks the # of parameters and the type of the parameters passed to the method and makes sure that you do not forget an argument.

If you want to omit arguments and still declare oFormTest then you can add default values for the arguments that you allow to skip like this (assuming the first 3 are mandatory):

public method say(fila as usual, columna as usual, ptext as usual, ppicture := NIL as usual, flgbold := NIL as usual, flgunderline := NIL as usual, flgreverse := NIL as usual) as void

or better, if you know the types that you are expecting then use:

public method say(fila as LONG, columna as LONG, ptext as STRING, ppicture := "" as STRING, flgbold := FALSE as LOGIC, flgunderline := FALSE AS LOGIC, flgreverse := FALSE as LOGIC) as void

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply