Page 1 of 1
Access to 'main' stuff from a module
Posted: Thu Nov 14, 2024 7:32 pm
by infratec
Again I had to solve a problem with a module and an enumeration, which should extend an enumeration (event) from the main program.
I solved it at least with a variable which is set from the main program.
A nicer solution would be to add a main:: 'namespace' to allow access to all global stuff of the main code.
Maybe then it is possible to do something like this:
Code: Select all
DeclareModule XYZ
Enumeration main::event
#PostEvent_FromModuleXYZ
Endenumeration
...
Re: Access to 'main' stuff from a module
Posted: Thu Nov 14, 2024 8:21 pm
by Fred
You should be able to do a 'Common' module to put all your common stuff between modules and main, and then use UseModule Common in your module which needs it and UseModule Common in the main file.
Code: Select all
DeclareModule Common
#PB_CustomEvent = 5
EndDeclareModule
Module Common
EndModule
DeclareModule MyModule
EndDeclareModule
Module MyModule
UseModule Common
Debug #PB_CustomEvent
EndModule
UseModule Common
Debug #PB_CustomEvent
Re: Access to 'main' stuff from a module
Posted: Thu Nov 14, 2024 9:50 pm
by infratec
I know this solution, but ...
I had to extend and older very large program.
I had to add a server plugin.
It is simply to much work to rewrite the old large program to use a common module, because of other pbi files which were done without module.
And I'm not sure if I can use named Enumerations with the common module.
I think it is not possible.
Re: Access to 'main' stuff from a module
Posted: Thu Nov 14, 2024 10:29 pm
by ChrisR
You can use named Enumerations with the common module, as long as UseModule Common is done before Enumerations
Code: Select all
DeclareModule Common
Enumeration Name
EndEnumeration
Debug "DeclareModule Common: " + #PB_Compiler_EnumerationValue
EndDeclareModule
Module Common
Enumeration Name
#NameCommon
EndEnumeration
Debug "Module Common: " + #NameCommon
EndModule
DeclareModule MyModule
UseModule Common
Enumeration Name
#NameDeclareMyModule
EndEnumeration
Debug "DeclareModule MyModule: " + #NameDeclareMyModule
EndDeclareModule
Module MyModule
Enumeration Name
#NameMyModule
EndEnumeration
Debug "Module MyModule: " + #NameMyModule
EndModule
UseModule Common
Enumeration Name
#NameMain
EndEnumeration
Debug "Main: " + #NameMain
Re: Access to 'main' stuff from a module
Posted: Fri Nov 15, 2024 7:47 am
by infratec
Ah ...
a modified clearing example:
Code: Select all
DeclareModule Common
Enumeration Name
EndEnumeration
EndDeclareModule
Module Common
Enumeration Name
#Test1
#NameCommon
EndEnumeration
Debug "Module Common: " + #NameCommon
EndModule
DeclareModule MyModule
UseModule Common
Enumeration Name
EndEnumeration
EndDeclareModule
Module MyModule
Enumeration Name
#NameMyModule
EndEnumeration
Debug "Module MyModule: " + #NameMyModule
EndModule
UseModule Common
Enumeration Name
#Test2
#NameMain
EndEnumeration
Debug "Main: " + #NameMai
You have to use an empty Enumeration in every Declare part of a module.
Re: Access to 'main' stuff from a module
Posted: Fri Nov 15, 2024 12:40 pm
by DarkDragon
Is this propagated enumeration really necessary? If it's for Gadgets or PB objects use PB_Any and you're not depending on Enum propagation anymore. Or use a Hashmap to generate event numbers during runtime. In ERPs there's one instance managing number circles like bill numbers or similar.
Re: Access to 'main' stuff from a module
Posted: Fri Nov 15, 2024 6:08 pm
by ChrisR
infratec wrote: Fri Nov 15, 2024 7:47 am
You have to use an empty Enumeration in every Declare part of a module.
The empty Enumeration seems only required in the common module declaration, to initialize the Enumeration name (Common::Name).
And in other modules declaration, "UseModule Common" seems to be enough.
Actually, I did as you do, with a variable which is set from the main program.
As I use constants and not PB_Any, I'll probably use it now that I'm re-reviewing it.
Code: Select all
DeclareModule Common
Enumeration Name
EndEnumeration
EndDeclareModule
Module Common
Enumeration Name
#Test1
#NameCommon
EndEnumeration
Debug "Module Common: " + #NameCommon
EndModule
DeclareModule MyModule
UseModule Common
EndDeclareModule
Module MyModule
Enumeration Name
#NameMyModule
EndEnumeration
Debug "Module MyModule: " + #NameMyModule
EndModule
UseModule Common
Enumeration Name
#Test2
#NameMain
EndEnumeration
Debug "Main: " + #NameMain
Re: Access to 'main' stuff from a module
Posted: Fri Nov 15, 2024 7:10 pm
by infratec
DarkDragon wrote: Fri Nov 15, 2024 12:40 pm
Is this propagated enumeration really necessary?
I add a module which sends a custom PostEvent().
There are already custom PostEvents() in the old program via
Code: Select all
Enumeration event #PB_Event_FirstCustomValue
So I want to continue the enumeration inside of the module.
Re: Access to 'main' stuff from a module
Posted: Fri Nov 15, 2024 7:53 pm
by mk-soft
Default Common Module for Teams ...
Code: Select all
DeclareModule Common
Enumeration CustomEvent #PB_Event_FirstCustomValue
;
EndEnumeration
Enumeration CustomEventType #PB_EventType_FirstCustomValue
;
EndEnumeration
Enumeration Windows
;
EndEnumeration
Enumeration Menus
;
EndEnumeration
Enumeration MenuItems
;
EndEnumeration
Enumeration StatusBars
;
EndEnumeration
Enumeration Gadgets
;
EndEnumeration
; And More
EndDeclareModule
Module Common
EndModule