Solved

MDI Variables

Posted on 1998-10-11
1
216 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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

12 Experts available now in Live!

Get 1:1 Help Now