Solved

Global Variables

Posted on 1997-11-19
3
232 Views
Last Modified: 2010-04-04
Now here's an easy one for you guys (I hope).
I have 3 stringvar's declared in unit1 (in the main part,not in a procedure) which are updated in another unit (unit2). As soon as unit2 closes,the updates are cancelled and I have my old values back which,ofcourse,is not the general idea. I have tried using pointers,but still doesn't work and don't know either if that's the proper way of tacklin' this problem. Somebody have an explanation of what's going on for a 4GL homebound?
0
Comment
Question by:lizzzard
3 Comments
 

Accepted Solution

by:
TechStone earned 50 total points
ID: 1351013
First of all, I assume you are "using" unit1.  That is, in unit 2 you should have a line something like:

     uses unit2;

(There may be more things you are using on the same line)  This makes the variables in unit1 accessible in unit2.

If this is done correctly, it should work as you want.

I would suggest looking for variables with the same name declared in unit2, either in the main part or in the procedure where you are using them.  If you re-declare the variables, this creates a new variable, which will mask the global variable from unit1.


0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1351014
Hiya Lizzard

Put Unit1 in the Unit2's usage clause and from inside Unit2 reference the variable in Unit1 as follows:

Unit1.VariableName := blahblah (or whatever value)

I keep my variables in my Datamodule as it's "used" by almost all my forms.

Good luck with your project!
Pegasus
0
 

Author Comment

by:lizzzard
ID: 1351015
Pegasus:Indeed I didn't refer to unit1 as you said. Now it works.
PS. As Delphi knows which variable to update (just by Variable:=blabla) it seems a bit overdone to make it Unit1.Variable:=blabla. It makes quite a diffence though.
Thanks again.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question