關於NULL,nil,0

出處 : http://moodlove.blog.hexun.com.tw/83290396_d.html

用過C++的Delphi的程序員都知道,C++中的NULL在Delphi中為nil,意思是空指針

在C++中 為 (void*)0 在Dlephi中 為 Pointer(0)

但是,這不是絕對,因為Handle

在C++中Handle,是一個指針

在Delphi中Handle,被理解為一個整數了,於是一切差別就從這裏開始

先看一個函數吧! CreateWindow

在C++的申明為:

HWND CreateWindow(

LPCTSTR lpClassName, // pointer to registered class name

LPCTSTR lpWindowName, // pointer to window name

DWORD dwStyle, // window style

int x, // horizontal position of window

int y, // vertical position of window

int nWidth, // window width

int nHeight, // window height

HWND hWndParent, // handle to parent or owner window

HMENU hMenu, // handle to menu or child-window identifier

HANDLE hInstance, // handle to application instance

LPVOID lpParam // pointer to window-creation data

);

讓我們來看看有幾個指針(7個,返回值,前兩個參數,後四個參數)

讓我們再來看看在Delphi中的申明:

function CreateWindow(

lpClassName: PChar; // pointer to registered class name

lpWindowName: PChar; // pointer to window name

dwStyle:Integer; // window style

x: Integer; // horizontal position of window

y: Integer; // vertical position of window

nWidth: Integer; // window width

nHeight: Integer; // window height

hWndParent: Integer; // handle to parent or owner window

hMenu: Integer; // handle to menu or child-window identifier

hInstance: Integer; // handle to application instance

lpParam: Pointer // pointer to window-creation data

): Integer;

有幾個指針呢?(有三個,前兩個和最後一個參數)

如果在調用此函數時,誇張一點,將所有指針(以C++)全用NULL代替的話,在Delphi中,函數調用應是這樣的:

hWnd := CreateWindow( ’’, ’’, ws_Child, 0, 0, 100, 100, 0, 0, 0, nil); //此函數只是例子


可見如果NULL指的是Handle的話,在Delphi中,它等價與0;其他嗎?等價於nil

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值