I'm trying to convert an old pascal procedure from Delphi 6 into Delphi 11.2 Alexandria.
I have the below function which fills in the modulo table with multiples of A, modulo being an
Array [0..255, 0..19] of Byte.
procedure TForm.SetModulo(A: TCode128);
var
I, J, Remainder : Byte;
NPointerStart: PCardinal;
NPointer: PCardinal;
ModuloPointer: PCardinal;
WordPointer: PWord;
begin
NPointerStart:= Addr(A);
for I:= 0 to 255 do begin
NPointer:= Pointer(NPointerStart);
Remainder:= 0;
ModuloPointer:= Addr(Modulo[I][0]);
for J:= 0 to 3 do begin
ModuloPointer^:= ((NPointer^ * I) + Remainder); //<- Int Overflow error
WordPointer:= Pointer(NPointer);
Remainder:= ((WordPointer^ * I) + Remainder) div $10000;
Inc(WordPointer);
Remainder:= ((WordPointer^ * I) + Remainder) div $10000;
Inc(NPointer);
Inc(ModuloPointer);
end;
ModuloPointer^:= Remainder;
end;
end;
The procedure parameter TCode128 is Array[0..15] of Byte and is sent byte addresses
($12, $C4.......).
In delphi 11.2 I get an Integer Overflow error at ModuloPointer^:= ((NPointer^ * I) + Remainder);
The value of I is just 2 when it throws the error.
When I run the same procedure on Delphi 10.4.2 there is no integer overflow error and everything works just fine.
I genuinely can not think of what's going wrong here, I tried typecasting ModuloPointer, NPointer to Uint64and Modulo to Word but no go(probably makes no sense).
Am I missing something fairly simple or there have been some changes in the Delphi 11.2 IDE? Either ways how do we get around this and what's going wrong?
NPointerpoints to aCardinal, which is 4 bytes. SoNPointer^is the 32-bit integer starting atNPointer. You then double it, which may indeed overflow.{$Q-}to disable overflow checking for this code. I wrap up such code in{$Q-}...{$IFDEF OVERFLOWCHECKSON}{$Q+}{$ENDIF}whereOVERFLOWCHECKSONis defined in my common include file.