Question

The code snippet below demonstrates a problem I am having with with text IO and UInt64 type variables in Delphi XE2 recently re-installed from a recent ISO image file - the compile fails with an error message relating to a missing Text.ReadUInt64 function or procedure. If I replace the failing line with

  ReadLn(F,A);

then the program compiles, correctly writes

-1
18446744073709551615

to the text file, and then (as expected) fails on the second read with an EInOutError: "Invalid Numeric Input". Do I have a corrupt install or has someone failed to write a ReadUInt64 function? The only reference to ReadUInt64 that I can find in help is the following definition:

function ReadUInt64: UInt64; virtual;

in System.Classes.TBinaryReader.ReadUInt64. I'm not sure if this is the 'same' function or, if so, why it is virtual...

I am also a little confused by Help's reference to UInt64. It defines it as:

type UInt64 = Int64;

If this is correct, how does the compiler know to treat an UInt64 differently to an Int64 variable?

procedure TForm1.Button1Click(Sender: TObject);
var
  F : TextFile;
  A : Int64;
  B : Uint64;
begin
{
Compiler warns on following line with message:
[DCC Warning] Unit1.pas(32): W1012 Constant expression violates subrange bounds
}
  A := $FFFFFFFFFFFFFFFF;
  B := $FFFFFFFFFFFFFFFF;
  AssignFile(F,'test.txt');
  ReWrite(F);
  Writeln(F,A);
  Writeln(F,B);
  CloseFile(F);
  AssignFile(F,'test.txt');
  ReSet(F);
  ReadLn(F,A);
{
Fails to compile on following line with message:
[DCC Fatal Error] Unit1.pas(42): E2158 System unit out of date or corrupted: missing 'Text.ReadUInt64'
}
  ReadLn(F,B);
  CloseFile(F);
end;
Was it helpful?

Solution

See QC102876. This is a known bug, reported as Text.ReadUInt64 missing, with the description:

The compiler generates a call to Text.ReadUInt64, when an UInt64 should be read from a stream. The linker, however, complains that Text.ReadUInt64 is missing.

This issue (bug) is resolved in XE3 (build #17.0.4625.53395), according to QC.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top