form的創建問題(50分)

  • 主题发起人 主题发起人 suyi3026
  • 开始时间 开始时间
S

suyi3026

Unregistered / Unconfirmed
GUEST, unregistred user!
窗體為MDI-子窗體型的<br>procedure showform(form:tformclass;newform:tform);<br>begin<br>&nbsp; if &nbsp;newform=nil &nbsp;then<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;newform:=form.create(nil);<br>&nbsp; &nbsp; &nbsp;newform.show;<br>&nbsp; end<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; newform.brinrtofont;<br><br>end;<br><br>procedure TForm1.ab1Click(Sender: TObject);<br>begin<br>&nbsp;showform(tform2,form2);<br>end;<br>以上的代碼為什么可以創建無數個tform2的實例啊?我想只能創建一個tform2的實例啊?<br>誰能解釋下原因啊?
 
加个全局 bool吧
 
不會啊<br>拜托給個例子吧
 
procedure showform(form:tformclass;newform:tform);<br><br>改成<br>procedure showform(form:tformclass;var newform:tform);
 
唉<br>期待更好的回答
 
procedure showform(form:tformclass;newform:tform);<br><br>改成<br>procedure showform(form:tformclass;var newform:tform); &nbsp;<br>这个就是区别有没有var这个了,其差别是传值与传址。<br>你可以试试以下这个。<br>procedure OpenForm(FormClass: TFormClass; var fm;<br>&nbsp; AOwner: TComponent);<br>var<br>&nbsp; i: integer;<br>&nbsp; Child: TForm;<br>begin<br>&nbsp; &nbsp; for i := 0 to Screen.FormCount - 1 do<br>&nbsp; &nbsp; &nbsp; if Screen.Forms.ClassType = FormClass then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Child := Screen.Forms;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Child.WindowState = wsMinimized then &nbsp; &nbsp;//如已存在但最小化的窗口,将还原显示<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowWindow(Child.handle, SW_SHOWNORMAL)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(Child.handle, SW_SHOWNA);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (not Child.Visible) then Child.Visible := True;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Child.BringToFront;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Child.Setfocus;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TForm(fm) := Child;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; Child := TForm(FormClass.NewInstance);<br>&nbsp; TForm(fm) := Child; &nbsp;Child.Create(AOwner);<br>end;
 
在你的qq群里我回答了你了,<br>在onClose 事件里写form2:=nil;
 
后退
顶部