Structure global to multiple modules

Just starting out? Need help? Post your questions and find answers here.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Structure global to multiple modules

Post 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
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: Structure global to multiple modules

Post 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 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6315
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Structure global to multiple modules

Post by mk-soft »

Create a common module is the right way
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Denis
Enthusiast
Enthusiast
Posts: 779
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Structure global to multiple modules

Post 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.
A+
Denis
User avatar
mk-soft
Always Here
Always Here
Posts: 6315
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Structure global to multiple modules

Post 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 ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: Structure global to multiple modules

Post by kinglestat »

Thanks
Good idea re common module
but what happens to global variables? are they reset if used in another module?
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
mk-soft
Always Here
Always Here
Posts: 6315
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Structure global to multiple modules

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Denis
Enthusiast
Enthusiast
Posts: 779
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Structure global to multiple modules

Post 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...
A+
Denis
Post Reply