Page 1 of 1

Structure global to multiple modules

Posted: Thu May 22, 2025 4:09 pm
by kinglestat
This might be a stupid question but I created an include file which I add at the top of my file

Code: Select all

Structure stType
   code.a
   flag.a
   i.w
   ndx.u
EndStructure

Global Dim        gszATR.s( #LJTOKENS )

But the structure is not available if I don't add it inside the module
Is this a bug? Or am I missing something?

The irony is that if I re-create the structure inside the module it says structure already exists but it doesn't let me create a variable of that type

Re: Structure global to multiple modules

Posted: Thu May 22, 2025 4:23 pm
by Axolotl
This is by design. Nothing except the PB stuff can be created outside and used inside a module.
Recommendation: Use a Common Modul for that.
Warning: this does not following any design rules..

Code: Select all

DeclareModule Common 
  #Constant = 123 
  
  Structure TWhatEver 
    Name.s 
  EndStructure 
  Global Test.TWhatEver 
EndDeclareModule 

; can be empty, but must declared 
Module Common 
EndModule 


DeclareModule Main 
  UseModule Common 
EndDeclareModule 

Module Main
  Test\Name  = "Test" 
  Debug #Constant 
  Debug test\Name 
EndModule 

Re: Structure global to multiple modules

Posted: Thu May 22, 2025 4:45 pm
by mk-soft
Create a common module is the right way

Re: Structure global to multiple modules

Posted: Thu May 22, 2025 4:46 pm
by Denis
I don't know if it still rocks in 2025.

Create a resident file (x86 & x64) with the global structure, restart the compiler and the global structure will be available directly without declaring it.

Re: Structure global to multiple modules

Posted: Thu May 22, 2025 4:49 pm
by mk-soft
Denis wrote: Thu May 22, 2025 4:46 pm I don't know if it still rocks in 2025.

Create a resident file (x86 & x64) with the global structure, restart the compiler and the global structure will be available directly without declaring it.
But a resident file is cross-project ...

Re: Structure global to multiple modules

Posted: Thu May 22, 2025 5:17 pm
by kinglestat
Thanks
Good idea re common module
but what happens to global variables? are they reset if used in another module?

Re: Structure global to multiple modules

Posted: Thu May 22, 2025 6:16 pm
by mk-soft
kinglestat wrote: Thu May 22, 2025 5:17 pm Thanks
Good idea re common module
but what happens to global variables? are they reset if used in another module?
No, common global variable not reinit. Otherwise it doesn't make sense

Re: Structure global to multiple modules

Posted: Fri May 23, 2025 6:24 am
by Denis
mk-soft wrote: Thu May 22, 2025 4:49 pm
Denis wrote: Thu May 22, 2025 4:46 pm I don't know if it still rocks in 2025.

Create a resident file (x86 & x64) with the global structure, restart the compiler and the global structure will be available directly without declaring it.
But a resident file is cross-project ...
you're right mk-soft.
But there are more than 700 predeclared structures in PB resident files (windows version), so cross-project, and that certainly satisfies a lot of coders...