How to define an unsigned 64-bit integer in Delphi7?

TheNewbie picture TheNewbie · Jun 16, 2011 · Viewed 9.5k times · Source

In Delphi 7, int64s are signed, if I try to declare a hex constant larger than $8000000000000000 (eg, what is really an uint64) I get an error. Can you advise some workarounds, please?

Answer

Johan picture Johan · Jun 17, 2011

You can make a variant record like so

type muint64 = record
  case boolean of
    true: (i64 : int64);
    false:(lo32, hi32: cardinal);
end;

Now you can just use the cardinals to fill your uint64 with unsigned data.

The other option would be to use code like this:

const almostmaxint64 = $800000045000000; 
var muint64: int64;    
begin
   muint64:= almostmaxint64;
   muint64:= muint64 shl 1;
end