Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MDI Variables

Posted on 1998-10-11
1
Medium Priority
?
226 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

972 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