0
votes

I'm trying to adopt some Windows code to Android, but I am unsuccessful.

When I try to compile the following code, I get an error:

[DCC Error] There is no overloaded version of 'HexToBin' that can be called with these arguments

var
  BinaryStream: TMemoryStream;
  HexStr: String;
  WSocket: TWSocket;
begin
  HexStr := memo1.Text;
  BinaryStream := TMemoryStream.Create;
  try
    BinaryStream.Size := Length(HexStr) div 2;
    if BinaryStream.Size > 0 then
    begin
      HexToBin(PChar(HexStr), BinaryStream.Memory, BinaryStream.Size);
      HexStr:='';
      HexStr:=MemoryStreamToString(BinaryStream);
      memo1.Text:=HexStr;
      IdUDPClient1.Send(HexStr);
1
Why are you showing all the other code. Can't we just focus on the one line that doesn't compile? - David Heffernan
For a better understanding of what is happening in my code. Because I'm not sure that all properly coded. - AKYLA
@David Heffernan Sorry if something is not done properly, I'm new and don't quite understand how to correctly execute all - AKYLA

1 Answers

2
votes

For Android you have to use one of these overloads:

function HexToBin(const Text: PChar; TextOffset: Integer;
  var Buffer: TBytes; BufOffset: Integer; Count: Integer): Integer; overload;

function HexToBin(const Text: TBytes; TextOffset: Integer;
  var Buffer: TBytes; BufOffset: Integer; Count: Integer): Integer; overload;

You can best achieve this by using a TBytesStream instead of a TMemoryStream.

A valid call could then look like this:

var
  BinaryStream: TBytesStream;
  bytes: TBytes;
  HexStr: String;
begin
  HexStr := memo1.Text;
  SetLength(bytes, Length(HexStr) div 2);
  HexToBin(PWideChar(HexStr), 0, bytes, 0, Length(bytes));
  BinaryStream := TBytesStream.Create(bytes);
  ...