線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:7359
推到 Plurk!
推到 Facebook!

null=nil ?

答題得分者是:vitojeng
yaoyao01tw
一般會員


發表:28
回覆:17
積分:9
註冊:2003-01-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-02-13 12:54:51 IP:220.134.xxx.xxx 訂閱
不知道Delphi內Null 的保留字是null還是nil,兩者有無差異,請前輩們是否可以告知一下!

有點搞混了!
SleepWalker
一般會員


發表:16
回覆:20
積分:12
註冊:2004-06-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-02-13 16:54:22 IP:220.229.xxx.xxx 訂閱
Delphi 是 nil
VB 是 Null
意思是一樣的.
yaoyao01tw
一般會員


發表:28
回覆:17
積分:9
註冊:2003-01-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-02-13 17:57:29 IP:220.134.xxx.xxx 訂閱
Delphi 中好像也可以用Null,我查了線上說明!
Null function
See also


Returns a Null variant.
Unit
Variants
Category
Variant support routines
Delphi syntax:
function Null: Variant;
C syntax:
extern PACKAGE Variant __fastcall Null(void);
Description
Use Null to obtain a Null variant that can indicate unknown or missing data. Null Variants can be assigned to variant 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 EVariantTypeMismatch 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.
Delphi example:
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;
C example:
int Test(Variant v)
{
Variant q = v; // this is ok, since q is a variant
AnsiString msg;
if (VarIsNull(q))
msg = "q is a null variant";
else
msg = "q is not a null variant";
ShowMessage(msg);

return v; // this throws an exception!!!

}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Test(Null());

}
Except for comparisons, which always result in Boolean values, expressions involving Null variants always result in Null variants.
Note: The Null variant returned by the Null function is different from the nil constant in Delphi code and the NULL macro in C code. Neither nil nor NULL is a variant. The nil constant is an object reference that does not refer to any actual object. The NULL macro is a pointer that does not refer to any actual object or value.
SleepWalker
一般會員


發表:16
回覆:20
積分:12
註冊:2004-06-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-02-13 20:13:17 IP:61.224.xxx.xxx 訂閱
The reserved word nil is a special constant that can be assigned to any pointer. When nil is assigned to a pointer, the pointer doesnt reference anything.

Null represents the null Variant.
vitojeng
一般會員


發表:2
回覆:13
積分:13
註冊:2003-10-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-02-18 14:58:48 IP:59.105.xxx.xxx 訂閱
Delphi 內
  • nil 指的是空指標, 是保留字.
  • Null 是在 Variants.pas 內定義的一個常數(其實是一個 function), 用來表示 Variant 裡面 Null 值, Unassigned 也是相同的情形.

所以 C 裡面的 Null 在 Delphi 裡就是 nil.

===================引 用 文 章===================
不知道Delphi內Null 的保留字是null還是nil,兩者有無差異,請前輩們是否可以告知一下!

有點搞混了!
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-11-28 12:00:29 IP:125.215.xxx.xxx 訂閱
nil是专门用作指针里面的。表示指向空指针。
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
系統時間:2024-11-22 8:56:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!