由于现在我将FORM2设置为fsmdichild窗体后,然后我再用showmodel打开,然后提示错误。如果使用form2:=tform2.Create(self);form2.Show ;进行打开的话,每打开一次,就自动生成一个form2窗体,这样子非常不好,有时打开了多个form2都不知道。
问题如下:能否通过代码去实现,点击多次打开,也只能打开一个form2窗体。如何实现这个功能?

解决方案 »

  1.   

    var
    frm2:TForm2;
    i:integer;
        begin
              if Application.FindComponent(Form2)=nil then   //Form2没有打开
                begin
                frm2:=TForm2.Create(Application);
                frm2.Show;
                end
                else   //如果已经打开,则显示,不重复打开
                for  i:=0 to self.MDIChildCount-1 do
                begin
                if self.MDIChildren[i] is TForm2 then
                ShowWindow(MainForm.MDIChildren[i].Handle, SW_MAXIMIZE);
                end;
        end;