Solved

Global Variables

Posted on 1997-11-19
3
228 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now