I am trying to restructure my code into modules. But I am struggling with the "global" structures.
Let's consider the following code:
Code: Select all
DeclareModule Mod1
Structure CommonStructure
Number.i
String.s
EndStructure
Declare Mod1_Function(*par.CommonStructure)
EndDeclareModule
Module Mod1
Procedure Mod1_Function(*par.CommonStructure)
Debug *par\Number
EndProcedure
EndModule
DeclareModule Mod2
Structure CommonStructure
Number.i
String.s
EndStructure
Declare Mod2_Function(*par.CommonStructure)
EndDeclareModule
Module Mod2
Procedure Mod2_Function(*par.CommonStructure)
Debug *par\String
EndProcedure
EndModule
; Main Scope
Structure CommonStructure
Number.i
String.s
EndStructure
NewList Test.CommonStructure()
AddElement(Test())
Test()\Number=1
Test()\String="Test"
UseModule Mod1 ; this raises an error because the compiler inserts Commonstructure
UseModule Mod2 ; into the main scope in which it already exists
Mod1_Function(@Test())
Mod2_Function(@Test())
End
I can think of two solutions. Both kinda defeat the purpose of using modules. They are:
1. Give every structure an unique name:
- Main_CommonStructure
- Mod1_CommonStructure
- Mod2_CommonStructure
Not really what you would want. Difficult to update the structures too.
2. Don't use UseModule and use prefix Mod1::Mod1_Function() instead
Now you lose the autocomplete and it gives you also longer commands,
Maybe there is a better way. Any input is appreciated!
John