不兼容的类型 - TArray<System.Byte> & Byte

3

我已经将outputBuffer声明为Byte类型,并相应地使用它:

TFile.WriteAllBytes(outputPath, outputBuffer);

当我编译我的程序时,Delphi会输出以下信息:

[DCC错误] StormLib.pas(56): E2010 不兼容的类型:'System.TArray[System.Byte] and 'Byte'

我是否使用了错误/过时的数据类型来定义变量?我该怎么做才能让我的程序编译通过?

提前谢谢您!


2
TFile.WriteAllBytes(outputPath, TBytes.Create(outputBuffer)) 将写入您的 1 字节文件。 - David Heffernan
2个回答

8
请使用 TBytes。方法WriteAllBytes接受TBytes作为参数,它被定义为TArray<Byte>,因此是一个字节数组,而不仅仅是单个的Byte
var
  OutputPath: string;
  OutputBuffer: TBytes;
begin
  // use SetLength to set the length of your OutputBuffer
  // byte array, fill it somehow and then call WriteAllBytes
  TFile.WriteAllBytes(OutputPath, OutputBuffer);
end;

1

你的错误信息清楚地显示了不兼容的类型不是Byte和Byte,而是TArray<Byte>和Byte。坦白地说 - 这是预期的。字节数组比单个字节要多得多。

创建一个TArray<Byte>类型的变量,并使用它来包含该值。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接