Solved

MDI Variables

Posted on 1998-10-11
1
222 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 20 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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