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

Brian G brian at westwoodsvcs.com
Wed Feb 17 14:03:35 CET 2021


Yes I have tried, Cool way to add plugins. 

It took me a while to figure out the right way to name the component.. 
project name had to be 'myPlugin.plg' or some derivative... 
I kept making it MaPlg1 , which it found but crashed because it was also the component name .. lol 

I have attached a text file, as I look at your program. 

Suggest to use _new instead of running through all the plugins. 
_new is executed upon instantiation of an object. See text file. 

and add Dir(Component.path, "*"&plgid&"*") filter to dir so you don't check every file. 

lol .. my french is very rusty.. have not really used it since high school in Canada! 

I worked in Quebec for a while.. but still.. 

Your example Works just fine! 


So Yes I tried you program ;) 

Brian G 


From: "olivier coquet" <ocoquet at 3d-phenomen.fr> 
To: "Gambas mailing list" <user at lists.gambas-basic.org> 
Sent: Wednesday, February 17, 2021 12:31:27 AM 
Subject: Re: [Gambas-user] Sub and Function hijack ?? is this possible ? 

Hello Brian, 
Have you tried the code I sent and does it work for you? 
What do you think about it? 

friendship 
Olivier C. 

Le 17/02/2021 à 01:28, Brian G a écrit : 



It is trying to be dynamic with loaded classes on the fly, not bound at compile time 

The attached script gives a demo or what I think we are talking about. 
More like this example: 

class xx 
Public sub _Call() 
print "form" 
end 
Public sub MySub() 
Print "form MySub" 
end 
Public Sub _new() 
' stuff 
end 
end class 

class yy 
Public sub _Call() 
print "sub form" 
end 
Public sub MySub() 
Print "sub form MySub" 
end 
Public sub _new() 
' stuff 
end 
end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 
Public sub MySub() 
Print "sub sub form MySub" 
end 
Public sub _new() 
'stuff 
end 
end class 

'Of course we could load a library or componant before creating an instance of the contained class' 

Public sub main() 
dim cButtons as new variant[] 
dim oNew as variant 
oNew = new xx 
cButtons.add(oNew) 
oNew = new yy 
cButtons.add(oNew) 
oNew = new vv 
cButtons.add(oNew) 

for each mButton as object in cButtons 
' call the same interface for each class 
' Using the same object or button assigned to the form 
mButton() 
mButton.MySub() 
next 

cButtons[1]() 
cButtons[1].MySub() 

' mButton could be any object with the correct interface 
' display form with plugin button or redefined button 


end 

Thank You 
Brian G 


From: "Brian" [ mailto:brian at westwoodsvcs.com | <brian at westwoodsvcs.com> ] 
To: "Gambas mailing list" [ mailto:user at lists.gambas-basic.org | <user at lists.gambas-basic.org> ] 
Sent: Tuesday, February 16, 2021 4:19:49 PM 
Subject: Re: [Gambas-user] Sub and Function hijack ?? is this possible ? 

or like this: 



Thank You 
Brian G 

From: "Jeff P. Zacher" [ mailto:adsicks at gmail.com | <adsicks at gmail.com> ] 
To: "Gambas mailing list" [ mailto:user at lists.gambas-basic.org | <user at lists.gambas-basic.org> ] 
Sent: Tuesday, February 16, 2021 11:42:50 AM 
Subject: Re: [Gambas-user] Sub and Function hijack ?? is this possible ? 

If I run this code: 
' In Form1 
Public Sub Test() 
Print "form" 
End 


Public Sub Form_Open() 
Public sub _Call() 
print "form" 
end 

Public sub MySub() 
Print "form MySub"class xx 
end 

Public Sub _new() 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 

Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _new() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _new() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end 


Public sub _Call() 
print "form" 
end 

Public sub MySub() 
Print "form MySub"class xx 
end 

Public Sub _new() 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 

Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _new() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _new() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end 



Test() 

End 


' In Class1 

Public Sub Test() 
Print "class" 
Endclass xxPublic sub _Call() 
print "form" 
end 

Public sub MySub() 
Print "form MySub"class xx 
end 

Public Sub _new() 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 

Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _new() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _new() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end 



Public sub _Call() 
print "form" 
end 

Public sub MySub()Public sub _Call() 
print "form" 
end 

Public sub MySub() 
Print "form MySub"class xx 
end 

Public Sub _new() 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 

Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _new() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _new() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end 



Print "form MySub" 
end 

Public Sub _init() 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 
Public sub _Call() 
print "form" 
end 

Public sub MySub() 
Print "form MySub"class xx 
end 

Public Sub _new() 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 

Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _new() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _new() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end 



Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _init() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _init() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end sub 

end 




Thank You 
Brian G 

From: "Jeff P. Zacher" [ mailto:adsicks at gmail.com | <adsicks at gmail.com> ] 
To: "Gambas mailing list" [ mailto:user at lists.gambas-basic.org | <user at lists.gambas-basic.org> ] 
Sent: Tuesday, February 16, 2021 11:42:50 AM 
Subject: Re: [Gambas-user] Sub and Function hijack ?? is this possible ? 

If I run this code: 
' In Form1 
Public Sub Test() 
Print "form" 
End 


Public Sub Form_Open() 

Test() 

End 


' In Class1 

Public Sub Test() 
Print "class" 
End 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 

Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _init() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _init() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) class xx 
Public sub _Call() 
print "form" 
end 

Public sub MySub() 
Print "form MySub" 
end 

Public Sub _init() 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 

Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _init() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _init() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end sub 

end 




Thank You 
Brian G 

From: "Jeff P. Zacher" [ mailto:adsicks at gmail.com | <adsicks at gmail.com> ] 
To: "Gambas mailing list" [ mailto:user at lists.gambas-basic.org | <user at lists.gambas-basic.org> ] 
Sent: Tuesday, February 16, 2021 11:42:50 AM 
Subject: Re: [Gambas-user] Sub and Function hijack ?? is this possible ? 

If I run this code: 
' In Form1 
Public Sub Test() 
Print "form" 
End 


Public Sub Form_Open() 

Test() 

End 


' In Class1 

Public Sub Test() 
Print "class" 
Endclass xx 
Public sub _Call() 
print "form" 
end 

Public sub MySub() 
Print "form MySub" 
end 

Public Sub _init() 
' stuff 
end 

end class 

class yy 
Public sub _Call() 
print "sub form" 
end 

Public sub MySub() 
Print "sub form MySub" 
end 

Public sub _init() 
' stuff 
end 

end class 

class vv 
Public sub _Call() 
print "Sub Sub Form" 
end 

Public sub MySub() 
Print "sub sub form MySub" 
end 

Public sub _init() 
'stuff 
end 

end class 

Public sub main() 
dim cClasses as object[] 'get the classes instantiated 
cClasses.add(new xx) ' execute the init for each class 
cClasses.add(new yy) 
cClasses.add(new xx) 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end sub 

end 




Thank You 
Brian G 

From: "Jeff P. Zacher" [ mailto:adsicks at gmail.com | <adsicks at gmail.com> ] 
To: "Gambas mailing list" [ mailto:user at lists.gambas-basic.org | <user at lists.gambas-basic.org> ] 
Sent: Tuesday, February 16, 2021 11:42:50 AM 
Subject: Re: [Gambas-user] Sub and Function hijack ?? is this possible ? 

If I run this code: 
' In Form1 
Public Sub Test() 
Print "form" 
End 


Public Sub Form_Open() 

Test() 

End 


' In Class1 

Public Sub Test() 
Print "class" 
End 

for each mClass as object in cClasses 
mClass() 
mClass.MySub() 
next 


end sub 

end 




Thank You 
Brian G 


From: "Jeff P. Zacher" [ mailto:adsicks at gmail.com | <adsicks at gmail.com> ] 
To: "Gambas mailing list" [ mailto:user at lists.gambas-basic.org | <user at lists.gambas-basic.org> ] 
Sent: Tuesday, February 16, 2021 11:42:50 AM 
Subject: Re: [Gambas-user] Sub and Function hijack ?? is this possible ? 



If I run this code: 


' In Form1 


Public Sub Test() 

Print "form" 

End 


Public Sub Form_Open() 

Test() 

End 




' In Class1 

Public Sub Test() 

Print "class" 

End 


I get the following output: 

form 

What am I missing? This is what I would expect. 




If you want to overload, just create a class that inherts a form class and overload it.... 


On 2/15/21 10:58 AM, Brian G wrote: 

BQ_BEGIN

Are you adding dynamic classes as plugins? Not sure when this would be needed? Or are you defining classes on the fly in you code? 

Would be interesting to know how your using it! 

It is a simple way of writing once and basically having a sort of self modifying code. That is any module or class can change the actual destination of a call without the main process knowing about it. 


Thank You 
Brian G 


From: "olivier coquet" [ mailto:ocoquet at 3d-phenomen.fr | <ocoquet at 3d-phenomen.fr> ] 
To: "Gambas mailing list" [ mailto:user at lists.gambas-basic.org | <user at lists.gambas-basic.org> ] 
Sent: Monday, February 15, 2021 5:35:10 AM 
Subject: Re: [Gambas-user] Sub and Function hijack ?? is this possible ? 

Le 14/02/2021 à 21:44, Jussi Lahtinen a écrit : 

BQ_BEGIN



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

BQ_BEGIN

Le 13/02/2021 à 20:45, Christof Thalhofer a écrit : 

BQ_BEGIN

BQ_BEGIN

Am 13.02.21 um 09:08 schrieb olivier coquet: 

BQ_BEGIN

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. 

BQ_BEGIN

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? 

BQ_END
No. The only possibility is that in Fmail you call this: maclasse.maprocedure() 

BQ_END
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 [ http://www.deepl.com/Translator | www.DeepL.com/Translator ] (free version) 

BQ_END


BQ_END


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 

BQ_END


Hi jussi, 

Thank you for your response, 
To answer your question, I have been working for 3 months on a home automation project that involves the use of several elements. 
The first one, an http server that is simple to implement and that integrates perfectly with a gambas program has been made as a gambas component (see my messages about this) is perfectly operational. 
The second one is the main program that takes care of the management of the connected objects, the scenarios and the launch schedule of each scenario is also operational (well almost, still some bugs). 
The third one is a system that would allow to add functions at will to the main program without rewriting it. 
It is on this last point that I am working on, a plugin system that installs itself and joins the main program. To do this, I use a component that I made in a special way. 
Its functions: 
- Able to create new buttons on the interface of the main program. 
- Manage these buttons. 
- To be able to substitute its own functions and procedures to those of the main program without modifying it. 
- Do not disturb the main program if the plugin is not installed. 

Hence my last question and the answer I gave there this weekend 
So my plugin system is now operational, if someone is interested, I can send the sources of a test plugin and the sources of an example program implementing it. 

Friendship 
Olivier COQUET 


Translated with [ http://www.deepl.com/Translator | www.DeepL.com/Translator ] (free version) 


----[ [ http://gambaswiki.org/wiki/doc/netiquette | http://gambaswiki.org/wiki/doc/netiquette ] ]---- 

----[ [ http://gambaswiki.org/wiki/doc/netiquette | http://gambaswiki.org/wiki/doc/netiquette ] ]---- 

BQ_END


----[ [ http://gambaswiki.org/wiki/doc/netiquette | http://gambaswiki.org/wiki/doc/netiquette ] ]---- 


----[ [ http://gambaswiki.org/wiki/doc/netiquette | http://gambaswiki.org/wiki/doc/netiquette ] ]---- 

BQ_END





----[ http://gambaswiki.org/wiki/doc/netiquette ]---- 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210217/2f31c0e4/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plg_test_plugin_response
Type: application/octet-stream
Size: 4346 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210217/2f31c0e4/attachment-0001.obj>


More information about the User mailing list