Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incompatible Types - TArray<System.Byte> & Byte

I have declared outputBuffer as a Byte and used it accordingly:

TFile.WriteAllBytes(outputPath, outputBuffer);

When I compile my program, Delphi outputs:

[DCC Error] StormLib.pas(56): E2010 Incompatible types: 'System.TArray[System.Byte] and 'Byte'

Have I used the wrong/out-dated data type for my variable? What must I do to get my program to compile?

Thank you in advanced!

like image 376
ple103 Avatar asked May 19 '26 04:05

ple103


2 Answers

Use TBytes instead. The WriteAllBytes method takes TBytes which is defined as TArray<Byte> and so is an array of bytes, not just a single 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;
like image 124
TLama Avatar answered May 21 '26 03:05

TLama


You error message clearly shows that incompatible types are not Byte and Byte, but TArray<Byte> and Byte. Frankly - that is what expected. Array of bytes is much more than single byte.

Make variable of TArray<Byte> type and use it to contain the value.

like image 33
Arioch 'The Avatar answered May 21 '26 05:05

Arioch 'The



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!