null=nil ? |
答題得分者是:vitojeng
|
yaoyao01tw
一般會員 發表:28 回覆:17 積分:9 註冊:2003-01-28 發送簡訊給我 |
|
SleepWalker
一般會員 發表:16 回覆:20 積分:12 註冊:2004-06-21 發送簡訊給我 |
|
yaoyao01tw
一般會員 發表:28 回覆:17 積分:9 註冊:2003-01-28 發送簡訊給我 |
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 發送簡訊給我 |
|
vitojeng
一般會員 發表:2 回覆:13 積分:13 註冊:2003-10-06 發送簡訊給我 |
Delphi 內
所以 C 裡面的 Null 在 Delphi 裡就是 nil. ===================引 用 文 章=================== 不知道Delphi內Null 的保留字是null還是nil,兩者有無差異,請前輩們是否可以告知一下! 有點搞混了! |
zhouying82
高階會員 發表:150 回覆:272 積分:189 註冊:2004-03-16 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |