Error in 32 bit calulation

Hi Bruno

i am testing an encryption routine in webcore and get crazy results and/or exceptions.
Finally i could shrink the code to following example:

procedure test;
var a,b,c  : longword;              // or cardinal
   a:=2654435769;                      // $9E3779B9
   b:=1147237152;                      // $44617320
   c:=a xor b;

//   c should be  3663071897        $DA560A99

in a windows exe i see a correct result but not in webcore.
i tested with the internal debugger (in win64 and chrome).

following error is raised:

Uncaught [object Object] | fMessage:: fHelpContext::0 
at http://localhost:8000/Login/Login.js [469:9]X

The Internal debugger in chrome sometime shows a crazy result:  


But longwords or cardinal should always be positive !!!

Any idea ?


Error is raised because range check is on by   {$R+} in code.

Seems js code is working integer here.

You can see this in the debugger too.
C is shown as integer

procedure Tftest.WebButton1Click(Sender: TObject);
   a,b,c,d : cardinal;         a = 2654435769,   b = 114723152,  c = -631895399,   d = 0

   a:=2654435769;     a = 2654435769
   b:=1147237152;     b = 1147237152
   c:=a xor b;        c = -631895399


Attachment 2


There is a general problem with logical operations on 32 bit in webcore.

Try following:

procedure Tfanmeldung.WebButton1Click(Sender: TObject);
  x,y,a,b : longword;    x = 0, y = -2147483648, a = 2147483649, b = -2147483647

   x:=0;                        x = 0
   y:=$80000000;        y = -2147483648
   a:=y+1;                    a = 2147483649

   y:=x or $80000000;   y = -2147483648, x = 0
   b:=y+1;                      b = -2147483647  

   a:=a;   // dummy

Run this step by step with the internal debugger.

As you see a and b are different.
In case 1 y seems to be correct because a:=y+1 is calculated correct.
In case 2 y seems to be the same but b:=y+1 is different and wrong.
In both cases the debugger displays y as negativ.
Seems that logical operations like OR are treated as integer internally.

Please run the same example with {R+}:

procedure Tfanmeldung.WebButton2Click(Sender: TObject);
  x,y,a,b : longword;           x = 0, y = 2147483648, b = 0

   x:=0;                       x = 0
   y:=$80000000;       y = 2147483648

   y:=x or $80000000;

   a:=a;   // dummy

The debugger displays y as positiv !
a is not displayed (why?)  but you can see ist under Scope: a:=: 2147483649
which is correct.

y:=x or $80000000 creates a range check exception and execution is aborted.

We have asked the compiler engineers to investigate.

The compiler engineers made improvements in this area and this will be addressed in the next update of the compiler.