在Delphi中help提到 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. 被free掉的from的指针不为nil,但是它的data is not valid. 如果人工调用form1 := nil。 那样使用assigned(P)就不会出错。 我在程序中也遇到这样的问题。但是通常搂主的问题是不会发生的。程序员有义务保证自己写的东西在逻辑上保持一致。如果free了,还要调用诸如show之类的函数,说明自己也不知道自己在干什么。
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.
ShowMessage('空');
form1.free
form1 := nil
之后就可以用assigned函数了
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.
被free掉的from的指针不为nil,但是它的data is not valid.
如果人工调用form1 := nil。
那样使用assigned(P)就不会出错。
我在程序中也遇到这样的问题。但是通常搂主的问题是不会发生的。程序员有义务保证自己写的东西在逻辑上保持一致。如果free了,还要调用诸如show之类的函数,说明自己也不知道自己在干什么。