[fpc-pascal] THandle in code that must compile also with Delphi
Juha Manninen
juha.manninen62 at gmail.com
Thu Mar 20 16:19:09 CET 2014
On Thu, Mar 20, 2014 at 3:25 PM, Virgo Pärna <virgo.parna at mail.ee> wrote:
> I did try googling and it appears, that in 64 bit Delphi XE2 uses THandle
> as a result type. Anyway, in the case of error, it returns INVALID_HANDLE_VALUE,
> which is DWORD(-1).
> So, under Windows it would be possible to use same code, if you compare result
> against INVALID_HANDLE_VALUE. And you should be able safely cast return value to
> THandle for that (and use variable of that type).
> I really don't know, how it would work on linux, because sys_open seems to return
> int there.
Thanks Virgo for this note. I was just thinking of how to check for errors.
In many places our Delphi code has :
if Handle<>-1 then begin
...
end;
I will not define a new type after all, instead I will use THandle
everywhere and then compare against INVALID_HANDLE_VALUE which is
defined in Windows unit also for Delphi2007.
The only downside is that Delphi compiler will complain about
incompatible types (signed / unsigned) when assigning FileCreate()
etc. return values. I must use typecast then but it is OK.
Regards,
Juha
More information about the fpc-pascal
mailing list