7

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++.

2
  • Instead of checking Null values, you should try and catch exceptions thrown... since Null is a no according to your question... Commented Oct 19, 2018 at 8:12
  • 4
    @Ruks Don't think so. I can only assume that HANDLE means we are talking about winapi which does not use exceptions to indicate errors. Commented Oct 19, 2018 at 8:19

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@George: In the windows headers, it's 0.
@George The reference to HANDLE makes me believe that we are talking about NULL from the Windows headers
@Bathsheba David Heffernan Ah yep sorry, ready for the weekend :).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.