关于Nil和Null有什么不同(5分)

W

wjh_wy

Unregistered / Unconfirmed
GUEST, unregistred user!
我在经用的时候总是搞不清楚它们两个有什么区别,请各位高手,指点指点?先谢谢了。
 
nil是delphi的关键字,null是sql的关键字,二者都是指“空”。
 

我不敢指点。
类型不同。

 
delphi里
nil是指针型的吧
null是数值型的 你可以用2*null的吧
我记得是这样的。
 
nil在pascal表示空指针,相当与C中的null,都是指针类型的。

另外delphi中的null是Variant型的空值:
Null represents the null Variant.

Unit

System

Category

variant support routines

var Null: Variant;

Description

Use Null to indicate unknown or missing data. Null can be assigned to variables
in an application that must contain a null value. Assigning Null to a Variant
variable does not cause an error, and Null can be returned from any function
with a Variant return value.

Assigning Null to a variable of any type other than Variant causes either a
compile-time error or raises an EVariantError exception. For example, in the
following code the assignment of v, the Null Variant, to Variant q is
successful
whereas the conversion of Variant v, which is now Null, to the
integer return type of the Test function, raises an exception.

function Test(v: Variant): Integer;

var
q: Variant;
msg: string;
begin
q := v
{ this is ok, since q is a variant }
if VarIsNull(q) then
msg := 'q is a null variant'
else
msg := 'q is not a null variant';
ShowMessage(msg);

Result := v
{ this raises an exception!!!}

end;

procedure TForm1.Button1Click(Sender: TObject);

begin
Test(Null);

end;

Expressions involving Null always result in Null. Thus, Null is said to
損ropagate?through intrinsic functions that return Variant data types. If
any part of the expression evaluates to Null, the entire expression evaluates
to Null.
 
一般情况下你只会用到nil(在Dephi)
到了C下面就要记得用NULL
 
nil是使指针指向的内容为空!可以重新分配内存!而null不可以重新分配内存![8D]
 
nil是delphi的关键字,null是sql的关键字,二者都是指“空”。
 
同意zw84611
 
同意zw84611
 
delphi中空指针nil
C,C++空指针NULL
sql空null
 
coolbaby的最全面
 
谢谢各位了
 
多人接受答案了。
 
顶部