Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:21:01+00:00 2026-06-01T23:21:01+00:00

I want to access a main form variable from a class that is called

  • 0

I want to access a main form variable from a class that is called from the main from.
Something like this:

Unit1:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Unit2, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;
var
  Form1: TForm1;
  Chiled:TChiled;
const
 Variable = 'dsadas';
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Chiled.ShowMainFormVariable;
end;

end.

Unit2:

unit Unit2;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

  type
  TChiled = class
  private
  public
    procedure ShowMainFormVariable;
  end;
var
  Form1: TForm1;
implementation

procedure TChiled.ShowMainFormVariable;
begin
  ShowMessage(Form1.Variable);
end;
end.

if in Unit2 i add to uses Unit1 an circular errors pops up.

How to make the Unit1 to be GLOBAL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:21:02+00:00Added an answer on June 1, 2026 at 11:21 pm

    As other answers tell, you should use one of the units in implementation section.

    Suppose you chose in ‘unit2’ you’d use ‘unit1’ in implementation. then you need to devise a mechanism to tell the ‘TChiled’ how to access ‘Form1’. That’s because since you haven’t used ‘unit1’ in interface section of ‘unit2’, you cannot declare the ‘Form1:TForm1’ variable in interface section. Below is just one possible solution:

    unit2
    
    type
      TChiled = class
      private
        FForm1: TForm;
      public
        procedure ShowMainFormVariable;
        property Form1: TForm write FForm1;
      end;
    
    implementation
    
    uses
      unit1;
    
    procedure TChild.ShowMainFormVariable;
    begin
      ShowMessage((FForm1 as TForm1).Variable);
    end;
    

    then in unit1 you can set the Form1 property of TChiled before calling TChiled’s method:

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Chiled.Form1 := Self;
      Chiled.ShowMainFormVariable;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to access a integer and a string from a class to all
I want to access the text elements inside this textbox in GWT from the
I am trying to access a form which is not static from another class
I have a quesion about how to access main window's variable from popup window.
I have a main windows form and another form that inherits from it. The
I want to access variables of a form from another form. On clicking a
I created this User Control: I added that User Control to the main Form
I want to access a MySQL database and I want to read+write data from+to
i want to access or get the class which is present in different project.How
I want to access files in the /sys, to be exact in the /sys/class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.