Solved

Global Variables

Posted on 1997-11-19
3
230 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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