请教大家这个问题出在哪里?(8分)

  • 主题发起人 主题发起人 delphiboy
  • 开始时间 开始时间
D

delphiboy

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.N3Click(Sender: TObject);<br>begin<br>&nbsp; if findwindow('TTj_Form','报表生成器')=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; application.CreateForm(TTj_Form,Tj_Form);<br>&nbsp; &nbsp; Tj_Form.show ;<br>&nbsp; end else<br>&nbsp; begin<br>&nbsp; &nbsp; Tj_Form.Position :=poMainFormCenter ;<br>&nbsp; &nbsp; SetActiveWindow(findwindow('TTj_Form','报表生成器'));<br>&nbsp; end;<br>end;<br><br>我的目的是防止一个窗体出现多次,但为什么这样不行?
 
procedure TForm1.N3Click(Sender: TObject);<br>begin<br>&nbsp; if findwindow(nil,'报表生成器')=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; application.CreateForm(TTj_Form,Tj_Form);<br>&nbsp; &nbsp; Tj_Form.show ;<br>&nbsp; end else<br>&nbsp; begin<br>&nbsp; &nbsp; Tj_Form.Position :=poMainFormCenter ;<br>&nbsp; &nbsp; SetActiveWindow(findwindow(nil,'报表生成器'));<br>&nbsp; end;<br>end;<br>
 
不行啊,这样会报错。
 
为什么不这样用啊,我改了改;<br><br>//if findwindow(nil,'tj_form')=0 then<br>&nbsp; if tj_form=nil then<br>&nbsp; begin<br>&nbsp; &nbsp; application.CreateForm(TTj_Form,Tj_Form);<br>&nbsp; &nbsp; Tj_Form.show ;<br>&nbsp; end else<br>&nbsp; begin<br>&nbsp; &nbsp; tj_form.BringToFront;<br>&nbsp; &nbsp; //Tj_Form.Position :=poMainFormCenter ;<br>&nbsp; &nbsp; //SetActiveWindow(findwindow(nil,'tj_form'));<br>&nbsp; end;<br>***********要引用tj_form的单元。
 
if not assigned(Tj_Form) then<br>&nbsp; begin<br>&nbsp; &nbsp; application.CreateForm(TTj_Form,Tj_Form);<br>&nbsp; &nbsp; Tj_Form.show ;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; tj_form.BringToFront;<br>&nbsp; end;<br>end;<br>
 
多谢大家回答,ASSIGNED()的确可以,但是FINDWINDOW()为什么就不可以呢?
 
后退
顶部