delphi – Assigned vs <> nil
发布时间:2020-12-15 10:18:21 所属栏目:大数据 来源:网络整理
导读:If Assigned(Foo)和If(Foo?nil)之间是否有区别?如果是,那么应该何时使用它们 解决方法 几乎是一样的事情。 The official documentation状态 Assigned(P) corresponds to the test P nil for a pointer variable,and @P nil for a procedural variable. 因
If Assigned(Foo)和If(Foo?nil)之间是否有区别?如果是,那么应该何时使用它们
解决方法
几乎是一样的事情。
The official documentation状态
因此,如果P是普通指针,则P零和分配(P)完全相同。另一方面,如果P是一些程序,那么 var p: TNotifyEvent = nil; procedure TForm1.FormCreate(Sender: TObject); begin if Assigned(p) then p(Self); end; 将会一直工作 procedure TForm1.FormCreate(Sender: TObject); begin if @p <> nil then p(Self); end; 但 procedure TForm1.FormCreate(Sender: TObject); begin if p <> nil then p(Self); end; 甚至不会编译。因此,结论是P – nil和Assigned(P)完全相同,每次都工作! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |