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 6956995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:56:31+00:00 2026-05-27T14:56:31+00:00

I got Form1 with some variables and I want to pass it to another

  • 0

I got Form1 with some variables and I want to pass it to another Form3 where I’ll use it. So I have two questions.

  • How can I get access to the variable in another form? I suppose it will
    be similar to

    var newIdList:= Form1.idList
    
  • When var idList get value in

      procedure TForm1.Button1Click(Sender: TObject);begin
      idList:=strtoint(edit1.text);
      end
    

    and I show new form in another can I still get value in idList?

    procedure TForm1.Button2Click(Sender: TObject); 
    begin
    form1.hide;
    form3.show;
    end
    

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;
    
    type
      TForm1 = class(TForm)
        PageControl1: TPageControl;
        TabSheet1: TTabSheet;
        TabSheet2: TTabSheet;
        TabSheet3: TTabSheet;
        Label5: TLabel;
        Edit3: TEdit;
        Edit2: TEdit;
        Button3: TButton;
        Edit4: TEdit;
        Button2: TButton;
        Button1: TButton;
        Edit1: TEdit;
        Label1: TLabel;
        Label3: TLabel;
        Label2: TLabel;
        Edit5: TEdit;
        Label7: TLabel;
        Label6: TLabel;
        Button4: TButton;
        ListBox1: TListBox;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Edit4Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Edit1Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
    
      private
        { Private declarations }
      public
        { Public declarations }
        idList,imieList,nazwiskoList,adresList: TStringList;
      end;
    
    var
      Form1: TForm1;
      plik:TStringList;
      tempPlik:TextFile;
      st:string;
      linia_klient,linia_video:array[0..20] of string;
      id:integer;
    
    implementation
    
    uses Unit3;
    
    {$R *.dfm}
    
    .
    .
    .
    
    procedure TForm1.FormCreate(Sender: TObject);
    var i:integer;
    begin
    Edit1.Text:='Witaj, Podaj ID klienta';
    Label1.Caption:='ID Klienta';
    idList:=TStringList.Create;
    imieList:=TStringList.Create;
    nazwiskoList:=TStringList.Create;
    adresList:=TStringList.Create;
    
    if (FileExists('idList.txt')=true) then idList.LoadFromFile('idList.txt') else idList.SaveToFile('idList.txt');
    if (FileExists('imieList.txt')=true) then imieList.LoadFromFile('imieList.txt') else imieList.SaveToFile('imieList.txt');
    if (FileExists('nazwiskoList.txt')=true) then nazwiskoList.LoadFromFile('nazwiskoList.txt') else nazwiskoList.SaveToFile('nazwiskoList.txt');
    if (FileExists('adresList.txt')=true) then adresList.LoadFromFile('adresList.txt') else adresList.SaveToFile('adresList.txt');
    
    AssignFile(tempPlik,'video.txt');
    Reset(tempPlik);
    i:=0;
    While Not Eof(tempPlik) do
      begin
        Readln(tempPlik,linia_video[i]);
        inc(i);
      end;
    
    CloseFile(tempPlik);
    end;
    
    
    
    procedure TForm1.Button4Click(Sender: TObject);
    begin
      //Form1.Hide;
      Form3.Show;
    end;
    
    end.



unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
Form3.Hide;
//Form1.Show;
end;



procedure TForm3.FormShow(Sender: TObject);
begin

Label4.Caption:= intToStr(idList.Count);
end;

end.
  • 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-05-27T14:56:31+00:00Added an answer on May 27, 2026 at 2:56 pm

    (I will assume that each form resides in its own unit.) First, you have to make sure that idList is accessible to other units. For example,

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
    
    type
      TForm1 = class(TForm)
      private
        { Private declarations }
        idList: integer;
      public
        { Public declarations }
      end;
    

    will not do, but

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
    
    type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
        idList: integer;
      end;
    

    is OK. In such case, all you need to do in Unit2 is to add Unit1 to its ‘uses list’ (press Alt+F11, or use File/’Use Unit…’, while in Unit2 or while editing Form2). Then you can use Form1.idList to access the variable anywhere inside Unit2. (Form1 is the global instance variable of TForm1 in Unit1).

    For example,

    unit Unit2;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm2 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form2: TForm2;
    
    implementation
    
    uses Unit1;     // <-- Add manually, or press Alt+F11 (or use File/'Use Unit...')
    
    {$R *.dfm}
    
    procedure TForm2.Button1Click(Sender: TObject);
    begin
      ShowMessage(IntToStr(Form1.idList));
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a form with textboxes and I want to run some server side
I've got some javascript that I want to attach to forms and to HTML
I've got form information captured and have built a URL to another website. How
I got this application from the internet and I want to add some modifications.
I've got a form inside a table that has some Javascript validation. The table
I've got my main form Form1 running the main bulk of my program. I
I got a form in Django but when I use {{ form.as_p }} it
I have got a form into which information is entered, and a drop down
I'm having some trouble with the idea of accessing variables from other classes. I
I have a web-app consisting of some html forms for maintaining some tables (SQlite,

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.