Solved

MDI Variables

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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