我已经将outputBuffer
声明为Byte
类型,并相应地使用它:
TFile.WriteAllBytes(outputPath, outputBuffer);
当我编译我的程序时,Delphi会输出以下信息:
[DCC错误] StormLib.pas(56): E2010 不兼容的类型:'System.TArray[System.Byte] and 'Byte'
我是否使用了错误/过时的数据类型来定义变量?我该怎么做才能让我的程序编译通过?
提前谢谢您!
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;
你的错误信息清楚地显示了不兼容的类型不是Byte和Byte,而是TArray<Byte>和Byte。坦白地说 - 这是预期的。字节数组比单个字节要多得多。
创建一个TArray<Byte>类型的变量,并使用它来包含该值。
TFile.WriteAllBytes(outputPath, TBytes.Create(outputBuffer))
将写入您的 1 字节文件。 - David Heffernan