5,927
社区成员




//form1的代码
uses Unit2;
{$R *.dfm}
procedure TForm1.ClickOpenForm(formname:string); 自定义的用字符串打开form的过程
var
myformclass:TFormClass;
aform:TForm;
begin
myformclass:=TFormClass(FindClass(formname));
aform:=Tform(TFormClass(FindClass(formname)));
if GetClass(TFormClass.ClassName)<>nil then
begin
aform:=myformclass.Create(Application);
try
aform.ShowModal;
finally
aform.Free;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ClickOpenForm('Tform2'); //将想要ShowModal的窗体名称传给自定义过程
end;
initialization
RegisterClass(Tform2);
end.
//form2的代码
procedure TForm2.Button1Click(Sender: TObject);
begin
Form2.Edit1.Text:='hello'; //这样给edit1.text赋值,没反应.
//Self.Edit1.Text:='hello'; //这样给edit1.text赋值,可以.
//Edit1.Text:='hello'; //这样给edit1.text赋值,也没问题.
//在form2内需要打开窗体form3 在form3内的button1的click事件内写代码 Form2.Edit1.Text:='hello'; 也是不行的....
end;