MDI程序中如何防止一个MDICHILD窗体的多个实例化。另外我想请问:
  如何在窗体关闭时显示确认对话框,选“确定”就关,选“取消”不做任何操作。最好给个例子,谢谢各位了。

解决方案 »

  1.   

    if assigned(Child01) then showmessage('已经创建')
    else Application.CreateForm(TChild01,Child01);注意在Child01的OnClose中写:
    Action:=caFree;
    Child01:=nil;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
     if MessageDlg('确定要关闭吗?',mtConfirmation,[mbYes,mbNo],0)=mrYes then
     CanClose:=true
     else CanClose:=false;
    end;
      

  2.   

    如果不是dll mdichildform 可以以如下方式创建:
    procedure createchildform;
    var
    i:integer;
    begin
     with application.mainform do
     begin
    //扫描当前是否有欲创建的窗体存在,如果有将其置前,否则创建
       for i := 0 to  mdichildcount - 1 do
         if mdichildren[i].classname = _will_create_child_form.classname then
    begin
            mdichildren[i].bringtofront;
            exit;
         end;
       _will_create_child_form := T_will_create_child_form.create(application);
    end;
    end;