Crusiatus Black,
Your code is excellent, as I could make it working well. See example below. Thank you!
The reason I am asking this is that I am building a kind of desktop, like the Windows desktop, where there are icons. My idea is identical to Windows: right click to add an icon, then tell the program name to be executed when the icon is clicked. In the example, I have made a simple input for easiness to the forum, but in my application it will be choosen from a list. The result is the same: the procedure name is stored in a variable. I was then wondering how to launch it. An external .EXE program is not a problem because you use RunProgram(Proc.s) but when it is an internal procedure it does not work the same way.
Code: Select all
Structure STRPROCENTRY
lpProcAddress.l
szProcName.s
EndStructure
NewList SG_Procedures.STRPROCENTRY()
Procedure SG_CallProc(szName.s)
Shared SG_Procedures.STRPROCENTRY()
ForEach SG_Procedures()
If LCase(szName) = SG_Procedures()\szProcName
CallFunctionFast(SG_Procedures()\lpProcAddress)
EndIf
Next
EndProcedure
Macro AddProcedure(A,B)
AddElement(SG_Procedures())
SG_Procedures()\lpProcAddress = A
SG_Procedures()\szProcName = LCase(B)
EndMacro
Procedure HelloWorld()
MessageRequester("Hello", "World")
EndProcedure
Procedure GoodbyeEarth()
MessageRequester("Goodbye", "Earth")
EndProcedure
AddProcedure(@HelloWorld(), "HelloWorld()")
AddProcedure(@GoodbyeEarth(), "GoodbyeEarth()")
Win = OpenWindow(#PB_Any, 0, 0, 800, 100, "Title", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
T=TextGadget(#PB_Any, 120,56,100,20,"Procedure Name:")
ProcName = StringGadget(#PB_Any, 260, 50, 300, 25, "")
BtnOk = ButtonGadget(#PB_Any, 650, 50, 100, 30, "Execute")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = #True
Case #PB_Event_Gadget
Select EventGadget()
Case BtnOk
Proc.s = GetGadgetText(ProcName)
SG_CallProc(Proc.s)
EndSelect
EndSelect
Until Quit
Note that I added a procedure GoodbyeEarth() to test it well. I now hope to be able to add parameters as well.