[Gambas-user] Sub and Function hijack ?? is this possible ?

Jussi Lahtinen jussi.lahtinen at gmail.com
Sun Feb 14 21:44:36 CET 2021


On Sun, Feb 14, 2021 at 10:05 AM olivier coquet <ocoquet at 3d-phenomen.fr>
wrote:

> Le 13/02/2021 à 20:45, Christof Thalhofer a écrit :
>
> Am 13.02.21 um 09:08 schrieb olivier coquet:
>
>
> A question to specialists, is it possible to hijack a procedure or
> function?
> Let me explain:
> in my FMain class, I have a procedure:
>
> public sub maprocédure()
>
> This "é" should nor be allowed in the name of a symbol.
>
>
> print "toto"
> end sub
>
> in a maclasse class, I have a second procedure:
> public sub maprocédure()
> print "titi"
> end sub
>
> I would like that during a call: maprocédure() in the FMain class, it is
> the one of the maclasse class that runs and not the one of FMain.
>
> Is this possible?
> and how?
>
> No. The only possibility is that in Fmail you call this:
> maclasse.maprocedure()
>
> Hello Christof and thank you for your answer.
>
> As I'm French, I'm stubborn :)
> So I dug a little bit into the problem and I found a solution.
>
> Just declare a public variable (*varfct*) of type object in fmain and initialize it with "Me".
> In Fmain we call the procedure in this way:
> *varfct.maprocedure()*
>
> In the main() of the class added next, I change the value of *varfct* by "Me" (the one of the new class), and it's done, the call changes destination without changing the main() code.
>
> Not very elegant but it works.
>
> Friendship
> Olivier Coquet
>
> Translated with www.DeepL.com/Translator (free version)
>
>
>
I don't quite understand what you are trying to achieve, but "Me" can refer
to any class (here FMain or maclasse).
So, even when your variable name stays the same (varfct), you are
essentially doing the same as this:

FMain.maprocedure
maclasse.maprocedure

or perhaps more enlightingly:

Dim hObj as object

hObj = FMain
hObj.maprocedure

hObj = maclasse
hObj.maprocedure


Jussi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210214/0922af51/attachment.htm>


More information about the User mailing list