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

x
?
Solved

MDI Variables

Posted on 1998-10-11
1
Medium Priority
?
223 Views
Last Modified: 2010-04-06

I have an MDI application.  This application has a window
of type TExplain_Graph.  I will allow the user to open as many of these windows as they want.  Each window will have a set of variables.  For this example (see code below), assume one variable called StatusFlag.  Any routine associated with this form needs to be able to access StatusFlag.

The problem I am running into is that EACH COPY OF THIS FORM will have it's own variables, with the same name, but with different values.

This is NOT the behavious that I am seeing.  

Let's walk through a sample.  I initially set the value of StatusFlag on FormCreate.  When I first enter FormCreate, StatusFlag is null, or empty.  I set the value in the routine.

If I then open a second copy of the window, then when I get to the FormCreate, the StatusFlag has the same value that was set by the First copy of the window.  VARIABLES ARE BEING SHARED BETWEEN WINDOWS.  This is not what I want.

Here's a copy of how I have the variable defined:
-----------------------------------------------------------
unit Explain_Graph_Form;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ...

type
  TExplain_Graph = class(TForm)
    ...

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var {Global}
  Explain_Graph: TExplain_Graph;

implementation

uses SQL_Form, Oracle_DataMod1, Main, DataModStuff;

var {Local}
   StatusFlag : String;

{$R *.DFM}



procedure TExplain_Graph.FormCreate(Sender: TObject);

begin
StatusFlag := 'Level1';
end;

--------------------------------------------------------

How do I define StatusFlag so that:
1).  Within each COPY of a window, any routine can access the variable.
2).  Each copy of the window has the same "set" of variables, but different values

Thanks
George Spears
0
Comment
Question by:gspears060598
[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
1 Comment
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 80 total points
ID: 1342533
George,

You are seeing this behaviour because StatusFlag is defined as a global variable to the unit. This means that there is only one StatusFlag and every instance of TExplain_graph can see it.

Remove the global declaration of StatusFlag and put its declaration into the form class. e.g.

type
      TExplain_Graph = class(TForm)
        ...

      private
        { Private declarations }
       StatusFlag : String;
      public
        { Public declarations }
      end;

Now there is a StatusFlag for every instance of TExplain_form.

If you want StatusFlag visible from outside the form class then place the declaration in the public section.

Hope this helps,

Raymond.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

670 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