【问题标题】:Incompatible Types - TArray<System.Byte> & Byte不兼容的类型 - TArray<System.Byte> & Byte
【发布时间】:2012-10-08 11:24:28
【问题描述】:

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

TFile.WriteAllBytes(outputPath, outputBuffer);

当我编译我的程序时,Delphi 输出:

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

我是否为我的变量使用了错误/过时的数据类型?我必须做什么才能让我的程序编译?

谢谢你!

【问题讨论】:

  • TFile.WriteAllBytes(outputPath, TBytes.Create(outputBuffer)) 将写入您的 1 字节文件

标签: delphi delphi-xe


【解决方案1】:

请改用TBytesWriteAllBytes 方法采用 TBytes,它被定义为 TArray&lt;Byte&gt;,因此是一个字节数组,而不仅仅是一个 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;

【讨论】:

    【解决方案2】:

    您的错误信息清楚地表明不兼容的类型不是 Byte 和 Byte,而是 TArray 和 Byte。坦率地说 - 这是预期的。字节数组远不止一个字节。

    制作 TArray 类型的变量并使用它来包含值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-12
      • 2015-08-11
      • 2011-07-07
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多