dummzeuch 1505 Posted July 23, 2020 (edited) 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. Edited July 23, 2020 by dummzeuch Share this post Link to post
Stefan Glienke 2002 Posted July 23, 2020 (edited) Best solution would probably to change the type of segment_ptr but then probably the E2010 pops up somewhere else. Anyhow a simple hardcast will do what it did before they tightened the assignment rule in 10.2: p := TWordArray(segment_ptr); Also shouldn't FastReports have fixed that code some while ago given they support 10.2 and higher? Edited July 23, 2020 by Stefan Glienke 1 Share this post Link to post
Cristian Peța 103 Posted July 23, 2020 (edited) 44 minutes ago, Stefan Glienke said: Also shouldn't FastReports have fixed that code some while ago given they support 10.2 and higher? From what I see it's fixed like this: var p : PWord; Edited July 23, 2020 by Cristian Peța 1 Share this post Link to post
dummzeuch 1505 Posted July 23, 2020 (edited) 7 hours ago, Stefan Glienke said: shouldn't FastReports have fixed that code some while ago given they support 10.2 and higher? Sh*t I forgot to replace the function name. I guess they have, but that code is from a release a few years old, way before Delphi 10.x. Maybe we should have updated, but given the "fun" I just had with another component update, I decided to simply try and compile the sources. Edited July 23, 2020 by dummzeuch Share this post Link to post
Remy Lebeau 1396 Posted July 24, 2020 (edited) On 7/23/2020 at 1:13 AM, dummzeuch said: How else could that be resolved? I would use PWord: function SomeFunction(segment_ptr: Pointer; segment_count: Integer ): TSmallintArray; var i: Integer; p : PWord {absolute segment_ptr}; begin SetLength(Result, segment_count); p := PWord(segment_ptr); for i := 0 to segment_count-1 do begin Result[i] := SwapInt16(p[i]); // or, if POINTER_MATH is not available on PWord: // Result[i] := SwapInt16(p^); Inc(p); end; end; Edited July 24, 2020 by Remy Lebeau 1 Share this post Link to post