Najprościej moim zdaniem by było jakbyś tworzył okno dynamicznie i wtedy można przekazać w konstruktorze interesującą Cię wartość. Bez zmiennych globalnych itp. Wtedy wystarczy tak:
Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Przycisk;
void __fastcall PrzyciskClick(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit2.h
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
int liczba;
public: // User declarations
__fastcall TForm2(TComponent* Owner, int _liczba);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <time.h>
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//Konstruktor Form1
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PrzyciskClick(TObject *Sender)
{
srand(time(NULL));
liczba = rand()%3+1;
Form2 = new TForm2(this,liczba);
Form2->ShowModal();
delete From2;
Form2 = NULL;
}
//---------------------------------------------------------------------------
Unit2.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner, int _liczba)
: TForm(Owner)
{
//Konstruktor Form2
this->liczba = _liczba;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormCreate(TObject *Sender)
{
Label1->Caption = liczba;
}
//---------------------------------------------------------------------------
Nie sprawdzałem, bo aktualnie nie mam dostępu do Buildera, ale powinno działać.