The following code used to compile with Delphi 2007:
constructor TMyFile.Create(const _Filename: string);
begin
inherited Create(Integer(INVALID_HANDLE_VALUE)));
// ...
end;
In Delphi XE it fails with the error E1012: Constant expression violates subrange bounds.
The reason is the declaration of THandleStream.Create:
Delphi 2007:
constructor THandleStream.Create(AHandle: Integer);
Delphi XE2:
constructor THandleStream.Create(AHandle: THandle);
with
type
THandle = NativeUInt;
If I change it to
constructor TMyFile.Create(const _Filename: string);
begin
inherited Create(THandle(INVALID_HANDLE_VALUE)));
// ...
end;
It compiles in both, Delphi XE2 and Delphi 2007. In Delphi 2007 it causes a warning "W1012: Constant expression violates subrange bounds" and it causes a runtime error when the Delphi 2007 executable is called.
Is there any way I can change the code so it works in both Delphi versions without having to resort to IFDEFS ?