Delphi - an array of bytes for a string

In my Delphi VCL Form application, I have a procedure that has the TBuff parameter (defined earlier as a byte array ). Inside this procedure, I need to convert the parameter to a string.

procedure Form1.Convert(Collect: TBuff);
var 
   str: String;
begin
   str := SysUtils.StringOf(Collect);
end;

After compilation, I was warned about the presence of this compiler error:

Incompatible types: 'System.TArray <System.TByte>' and 'TBuff'

+4
source share
1 answer

The problem you are facing is that you defined your own type of byte array as follows:

type
  TBuff = array of Byte;

, . RTL, , RTL TBytes, TArray<Byte>.

, , TBuff TBytes. TBuff, , , , TBytes. , TBuff .

, , . StringOf, . TEncoding.

, - UTF-8, :

str := TEncoding.UTF8.GetString(ByteArray);

ANSI, :

str := TEncoding.ANSI.GetString(ByteArray);

StringOf , ANSI, - , .

+7

Source: https://habr.com/ru/post/1525391/


All Articles