procedure TForm1.Button1Click(Sender: TObject); var temp : TObject ; begin temp := Application.FindComponent('Form2'); if temp <> nil then with temp as Tform do begin show ; end ; end;procedure TForm1.Button2Click(Sender: TObject); var temp : TObject ; begin temp := Application.FindComponent('Form2'); if temp <> nil then with temp as Tform do begin close ; end ; end; 和 procedure TForm1.Button1Click(Sender: TObject); begin Form2.show ; end;procedure TForm1.Button2Click(Sender: TObject); begin Form2.close; end; 一样
IF FormExists('FORM2' )=FALSE THEN Application.CreateForm(FORM2,FORM2); procedure TForm1.Button1Click(Sender: TObject); begin FORM2.show ; end;procedure TForm1.Button2Click(Sender: TObject); begin FROM2.close; end;
frmDept := nil;
frmDept := TfrmDept.Create(nil);
frmDept.Align := alClient;
现在frmdept为一个字符串,我该怎么做?怎么根据字符串打开一个已经存在的窗口
var
temp : TObject ;
begin
temp := Application.FindComponent('Form2');
if temp <> nil then
with temp as Tform do
begin
show ;
end ;
end;procedure TForm1.Button2Click(Sender: TObject);
var
temp : TObject ;
begin
temp := Application.FindComponent('Form2');
if temp <> nil then
with temp as Tform do
begin
close ;
end ;
end;
和
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.show ;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.close;
end;
一样
temp则为nil
--------------------------------
窗体这样可以(用字符串打开) ,但如果是函数呢 ?即 :Function FName : Integer ;通过字符串来调用 ,即
s := 'FName' ;
通过S 来调用这个函数 如上要求应该不可能实现 ,请大家谈谈看法,谢谢
procedure TForm1.Button1Click(Sender: TObject);
begin
FORM2.show ;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
FROM2.close;
end;
var
tmpform: TFormClass;
tmpobject: TObject;
tmpstr: string;
begin
tmpstr:='Tform2'; //tmpstr就是你要传的字符
tmpform:=TFormClass(FindClass(tmpstr));
tmpobject:=tmpform.Create(nil);
(tmpobject as Tform).Show;
end;initialization
begin
registerclasses([Tform2]);
end;
end.
RTTI就是这样.
我来这里不是为了分的.
因为我从这里得到比分更重要的东西.