我做了一个窗体(窗体1): 这里窗体1: 一直是处在打开状态.  又做了别外 一个窗体(窗体2)。       窗体2: 调用 窗体1 : 方法:在窗体2 onshow  事件时用定义一个变量a:窗体1: 变量a :=  窗体1.Create(Application);   变量a.Parent :=窗体2;    在关闭 窗体后。判断 原来打开的窗体1 是否存在:  我用Assgin(窗体1) 来判断.. .... 结果这个返回的结果是False;   
为什么窗体1 是打开的。 结果是Fasle

解决方案 »

  1.   

    Assigned()释放的地方需要自己p := nil;否则Assigned返回true
      

  2.   

    楼上的: 这个我知道。。 我的意思是说: 在打开窗体2前我就先打开窗体1, 窗体1 为MDI 窗体.   窗体2 为模式窗体. 我关闭窗体2。 我再打开窗体1。  在打开前。我需要判断窗体1是否被打开。 如果打开:我就不要再创建窗体。 直接显示已经打开的窗体1. 如果没有打开。再创建。 我用Assgin(窗体1)  来判断窗体是否打开状态.  这里始终  窗体1 已经被创建了。 这是怎么回事/?????
      

  3.   

    判斷指針是否為nil應用函數Assigned()
    var P: Pointer;begin
      P := nil;
      if Assigned (P) then Writeln ('You won''t see this');
      GetMem(P, 1024); {P valid}
      FreeMem(P, 1024); {P no longer valid and still not nil}
      if Assigned (P) then Writeln ('You''ll see this');
    end;
    Delphi syntax:function Assigned(const P): Boolean;DescriptionUse Assigned to determine whether the pointer or procedure referenced by P is nil. P must be a variable reference of a pointer or procedural type. Assigned(P) corresponds to the test P<> nil for a pointer variable, and @P <> nil for a procedural variable.Assigned returns false if P is nil, true otherwise.Note: Assigned can't detect a dangling pointer--that is, one that isn't nil but no longer points to valid data. For example, in the code example for Assigned, Assigned won't detect the fact that P isn't valid.
      

  4.   

    窗体1打开窗体2,比如窗体2的名字是Form2,则IF Not AsSigned(Form2) Then
       Form2:=TForm2.Create(Application);
    Form2.ShowModal;也可以使用变量var a:TForm2; 则把上面的Form2改成a即可; 根据此道理自己去改吧;