Welcome! Log In Create A New Profile

Advanced

Using Globals

Posted by MediOffice 
Using Globals
July 26, 2023 02:15PM
In my WB28 app I have a page that lists customers and a page for editing a customer record. On the customers list/search page there is a search filter field. I store the value entered here in a global variable. So after editing a customer and the search page is displayed again it automatically fills in the search field from the global variable. It all works fine.

However, I'm wondering if there is a better way to do this. I have lots of these globals - and we are always told "globals are bad".

What does everyone else do?
Re: Using Globals
July 26, 2023 04:01PM
Hi,

customers are simply "data" in the database. With the bad "globals" the global varibles are meant. Global variables are defined either on project level or on window / page level like: InvoiceTotal is decimal(7,2). These aren't bad or good, as long as they're really needed they're OK. But one should avoid to declare global variables wherever they could be replaced by a variable on a lower level.

Back to your customers. It's quite OK to have them in a table on one page and edit a single customer on a second page. If there are many data files, some programs have up to 1000 or 1500 data files, and a data file consist of a few data items only then you could maintain a data file on a single window / page by combining the Table control and the edit controls on a single page / window.

Kind regards,
Guenter Predl
office@windev.at
JP
Re: Using Globals
July 26, 2023 04:25PM
I dont think there is a problem with using global variables, either at the project level or the individual window/page level. These are very useful variable types and exist for a reason. The problem is to avoid abusing them. My first rule is name them so that they are very easy to identify (not just by color) and see where they are declared. For example, project level global variables I prefix with the word "Project" or "System" and Window/Page level globals I prefix with the word "Window" or "Page". Be consistent with naming and usage and you will avoid must problems.

I think the problems with globals harks back to a time when the development tool's IDE did not color the variables and allowed variables to be redefined elsewhere in the application without warning. WinDev/WebDev IDE solves all those historical problems.
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: