IonicWind Software

IWBasic => General Questions => Topic started by: novi on February 24, 2011, 05:41:12 PM

Title: GLOBAL variables not recognized
Post by: novi on February 24, 2011, 05:41:12 PM
I am trying to create project which is in multiple source files.  Compiling and using subs from other source files works in the main file but I can not get the compiler to recognize my GLOBAL variables from the main file in my other added source files.  For example I need the GLOBAL WINDOW win_main variable to be defined also in the other source files so commands to the window will work in those other files.

Thanx for any help,
cheers.
Title: Re: GLOBAL variables not recognized
Post by: LarryMc on February 24, 2011, 06:05:47 PM
The PROJECTGLOBAL preprocessor switch allows using the same file to both define project-wide globals and define them as external when the file is $included into other project files.  for variables you want global

create a file called Globals.iwb (or eba) and put the following in it
'global variables accessable to all modules
PROJECTGLOBAL "on"
 window mywindow
 int blah
 string blahblah
PROJECTGLOBAL "OFF"

add the file to your project
Add the following line to the top of every other source file in your project
$include "globals.iwb"  ' or eba

-----------------------------------
for subs

create sub
global sub test(int param),int
'...blah blah
return x
endsub

In every other source file where you want to use the sub enter this line at the top of the source file
declare extern test(int param),int

Pretty simple and it is going to be even simpiler for global subs in ver 2.0

LarryMc