Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

delphi

uint64

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?

like image 731
TheNewbie Avatar asked Jun 16 '11 20:06

TheNewbie


2 Answers

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
like image 65
Johan Avatar answered Sep 26 '22 05:09

Johan


Without support from the compiler you don't have many options.

I'm presuming that you wish to pass a value to a function in some external DLL. You'll have to declare the parameter as a signed 64 bit integer, Int64. Then all you can do is pass in the signed value that has the same bit pattern as the desired unsigned value. Build yourself a little converter tool with a compiler that has support for unsigned 64 bit integers.

like image 43
David Heffernan Avatar answered Sep 26 '22 05:09

David Heffernan