Welcome! Log In Create A New Profile

Advanced

Global variables in Global Procedure sets

Posted by Malc 
Malc
Global variables in Global Procedure sets
September 30, 2008 07:00PM
Hi Guys


From the help file:

Variables global to a set of procedures

the global variables declared in the initialization process of a set of procedures can be used in all the processes:

of the different procedures found in the set.

of the current project.


As I understand this, if I create a reusable global procedure file (e.g. MyGlobals.wdg), and have a global variable declared in it (e.g. gsMyName), adding this file to a project makes that variable visible anywhere within the project.

But it doesn't. :confused:

Constants work fine, as do procedures/functions within the file.
I would have placed money on this working ok before.

I can get it to work by prefixing the variable with the procedure filename, but this is not how I read the help.


Any comments?


Cheers

Malc




Glenn Rathke
Re: Global variables in Global Procedure sets
September 30, 2008 07:09PM
Hi Malc,

I believe you are right in that is the way it works. What would happen if you had a global variable, nCnt in Proc1 and another global nCnt in Proc2. How would you differentiate between the two. I guess that is why it has to be the procname.variable.

You're right, the help doesn't read that way...

Glenn
Sohan
Re: Global variables in Global Procedure sets
September 30, 2008 07:37PM
Hi Malc,

Windev is a bit ambivalent in this. Declarations without instantiating anything (like structures) are globally available, others are not (like variables).

Put the declarations in a header file, and put the header file in the project initialisation code. This way you can even differentiate between variables that you want to be 'really' global (they are in the header file), and variables that should be prefixed with the procedure name (they are in the set of global procedures).

Cheers,
/sohan
John
Re: Global variables in Global Procedure sets
September 30, 2008 09:21PM
Hi Sohan,

Could you expound a bit more on using a header file. Sounds like it is some type of include file. What is the syntax for including a file?

Thank You
John
Sohan
Re: Global variables in Global Procedure sets
September 30, 2008 09:31PM
It's EXTERN. And yes, it is an include file.

Cheers,
/sohan
Georgio
Re: Global variables in Global Procedure sets
September 30, 2008 10:08PM
Malc,

You can use Sohan's example or to define a global variable, simply declare it "project code".

From the menu, go to: Project, then Project code.

I used this area to declare variables that will remain constant throughout the program.
ex. Company Name, address, settings, etc.

Georgio
Malc
Re: Global variables in Global Procedure sets
October 01, 2008 11:21AM
Hi Glenn

I believe you are right in that is the way it works. What would happen if you had a global variable, nCnt in Proc1 and another global nCnt in Proc2. How would you differentiate between the two. I guess that is why it has to be the procname.variable.


I see what you mean, but would expect a PUBL:IC declaration to handle that, and GLOBAL to mean the same as other languages. I find using GLOBAL in the windows and classes to be a tad confusing. Ditto with grids being called Tables. :rolleyes:

Cheers

Malc
Malc
Re: Global variables in Global Procedure sets
October 01, 2008 11:30AM
Hi Sohan


Put the declarations in a header file, and put the header file in the project initialisation code. This way you can even differentiate between variables that you want to be 'really' global (they are in the header file), and variables that should be prefixed with the procedure name (they are in the set of global procedures).


Done that and it works a treat. I thought the "include" files were only for constants!

Now on to a related issue which I will post under "Include files...", like where to put them!

Cheers

Malc



Edited 1 time(s). Last edit at 10/01/2008 01:06PM by Malc.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: