锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
Form1錛堜富Form錛夛紝Form1涓婃湁Button1錛岀偣鍑籅utton1鏄劇ずForm2銆?br>Form2涓婃湁涓涓猂adioGroup1鍜孍dit1錛屽湪Form2鐨凮nShow浜嬩歡涓紝
榪涜RadioGroup1->ItemIndex = StrToInt(Edit1->Text);璧嬪兼搷浣溿侲dit1->Text榛樿鍊?銆?br>Form2鏄劇ず鍚庯紝鍦ㄧ晫闈笂閫夋嫨涓嶴trToInt(Edit1->Text)涓嶅悓鐨勯夐」鍚庡叧闂璅orm2銆傚亣璁鵑夋嫨浜嗙浜岄」銆?br>鍥炲埌Form1錛岄噸鏂版墦寮Form2錛岃繖鏃跺簲璇ユ樉紺虹殑鏄疪adioGroup1->ItemIndex = 0錛?br>鍙槸緇撴灉鍗存樉紺轟負絎簩欏廣?br>
PS錛欶orm1錛孎orm2閮芥槸鑷姩鍒涘緩鐨凢orm銆?br>
From1.cpp浠g爜濡備笅
//----------------------------Head Begin-----------------------------------------------
#ifndef Unit1H
#define Unit1H
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------Head End------------------------------------------------
//---------------------------Cpp Begin------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->Show();
}
//--------------------------Cpp End-------------------------------------------------
Form2浠g爜濡備笅
//--------------------------Form2 Head Begin-------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TRadioGroup *RadioGroup1;
TEdit *Edit1;
void __fastcall FormShow(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
//-----------------------------Form2 Head End----------------------------------------------
//-----------------------------From2 Cpp Begin----------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormShow(TObject *Sender)
{
RadioGroup1->ItemIndex = StrToInt(Edit1->Text);
}
//------------------------------From2 Cpp End---------------------------------------------
瑙e喅鏂規硶錛?br>鍦═Form2::FormShow鍔犲叆RadioGroup1->SetFocus();
void __fastcall TForm2::FormShow(TObject *Sender)
{
RadioGroup1->SetFocus(); //鍔犲叆
RadioGroup1->ItemIndex = StrToInt(Edit1->Text);
}