Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Global Variables

Posted on 1997-11-19
3
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
TechStone earned 100 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 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