I need to migrate my C++ codes to Delphi. There are many checks to check if a given handle(HANDLE
) is NULL
or not in C++ codes. What is the equivalent constant that can be used in Delphi? It seems that null
in Delphi is different from NULL
in C++.
1 Answer
In the Windows C++ header files, NULL
is a macro that expands to 0
. This means that NULL
can be used in both numeric and pointer contexts, because the C++ language supports such usage.
However, for Delphi, the value 0
is used in numeric contexts, and the value nil
is used in pointer contexts.
Windows HANDLE
values are declared in Delphi as numeric types and so in place of C++ NULL
you should use 0
in Delphi.
3 Comments
Bathsheba
@George: In the windows headers, it's 0.
David Heffernan
@George The reference to
HANDLE
makes me believe that we are talking about NULL
from the Windows headersGeorge
@Bathsheba David Heffernan Ah yep sorry, ready for the weekend :).
Null
values, you shouldtry
andcatch
exceptions thrown... since Null is a no according to your question...HANDLE
means we are talking about winapi which does not use exceptions to indicate errors.