如下一段代码是一个BUTTON点击中的
Application.CreateFrom(Tfrom1,form1);
form1.show;
但这样有一个问题,就是我按几下BUTTON,TFROM1就会实实例化几次,也会显示几次。

解决方案 »

  1.   

    FUNCTION isHasForm(localform:string):boolean;
    var i:integer;
    begin
       for i:= 0 to  application.ComponentCount-1 do
       if  application.components[i].name = localform
          then BEGIN result:=true;EXIT;END;   result:=false;
    end;//判断是否含有form
      

  2.   

    if not Assigned(form1) then
      Application.CreateForm(TForm1, form1);
    form1.Show;
      

  3.   

    if not Assigned(form1) then
      Application.CreateForm(TForm1, form1);
    form1.Show;
      

  4.   

    if application.FindComponent('form1')<>nil then
      begin
        showmessage('該窗口已存在')
      end;
      

  5.   

    谢了,我找到了方法,我是用原子来实现的var K:word;
        H:Word;
    const WM_ACT=$FFFF;
    begin
      if GlobalFindAtom(PChar('RCJL_IS_FIND'))=0 then
      Begin
        K:=GlobalAddAtom(PChar('RCJL_IS_FIND'));
         Application.Initialize;
         Application.Title := '查找分类';
         application.CreateForm(TfrmFind,frmFind);
         Application.Run;
      End
      Else
         H:=FindWindow(nil,pchar('查找分类'));
         if H<>0 then SendMessage(H,WM_ACT,0,0);
         Application.Terminate;end.