Solved

Global Variables

Posted on 1997-11-19
3
234 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

624 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