判断一个TButton对象(mybtn)有没有被释放的问题?????(100分)

  • 主题发起人 主题发起人 kemble
  • 开始时间 开始时间
K

kemble

Unregistered / Unconfirmed
GUEST, unregistred user!
判断一个TButton对象(mybtn)有没有被释放,下面的语句是不是一样,哪个更确切??
1:
if not Assigned(mybtn) then
{do something...}

2:
if mybtn = nil then
{do something...}
多谢!!
 
1 is better ,Assigned 要判断 mybtn 是否为 nil
 
一样的,有空就看看帮助:
function Assigned(const P): Boolean;

Description

Use 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.
 
一样的,
1看着专业点儿,
2看着直观点儿。
 
同意以上几位的
 
后退
顶部