This code (from a 3rd party library) compiles fine in Delphi XE2 but does not in Delhi 10.2 (both compiling for Win32):
type
TWordArray = array of Word;
function SomeFunction(segment_ptr: Pointer; segment_count: Integer ): TSmallintArray;
var
i: Integer;
p : TWordArray;
begin
SetLength(Result, segment_count);
p := segment_ptr;
i := 0;
while ((i < segment_count)) do begin
Result[i] := SwapInt16(p[i]);
inc(i)
end;
end;
I get an error in the line that assigns segment_ptr to p:
[dcc32 Error] test.pas(197): E2010 Incompatible types: 'TWordArray' and 'Pointer'
Is there a compiler setting which allows that kind of assignment? (I didn't even know that this is possible).
How else could that be resolved?
My first attempt is this:
function SomeFunction(segment_ptr: Pointer; segment_count: Integer): TSmallintArray;
type
TWordArray0 = array[0..0] of Word;
PWordArray = ^TWordArray0;
var
i: Integer;
p: PWordArray;
begin
SetLength(Result, segment_count);
p := segment_ptr;
i := 0;
while ((i < segment_count)) do begin
Result[i] := SwapInt16(p^[i]);
inc(i)
end;
end;
This compiles and probably should work fine (haven't tried it), but it feels so 1990ies.