提问者:小点点

对UInt64感到困惑


下面的代码片段演示了我遇到的一个问题,即Delphi XE2中的文本IO和UInt64类型变量最近从最近的ISO映像文件中重新安装——编译失败,并出现与缺少Text. ReadUInt64函数或过程相关的错误消息。如果我用

  ReadLn(F,A);

然后程序编译,正确写入

-1
18446744073709551615

到文本文件,然后(如预期的那样)在第二次读取时失败,出现EInOutError:“无效的数字输入”。我是否有损坏的安装或有人无法编写ReadUInt64函数?我可以在帮助中找到对ReadUInt64的唯一引用是以下定义:

function ReadUInt64: UInt64; virtual;

在System. Class.TBinaryReader.ReadUInt64中。我不确定这是否是“相同”的函数,或者,如果是,为什么它是虚拟的…

我对帮助对UInt64的引用也有点困惑。它将其定义为:

type UInt64 = Int64;

如果这是正确的,编译器如何知道将UInt64与Int64变量区别对待?

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;

共1个答案

匿名用户

这是一个已知的bug,报告为Text. ReadUInt64缺少,说明如下:

当应该从流中读取UInt64时,编译器会生成对Text. ReadUInt64的调用。但是,链接器抱怨Text.ReadUInt64丢失。

根据QC,此问题(bug)已在XE3(build#17.0.4625.53395)中解决。