问题
I am upgrading an older version of Delphi to XE5, The older version uses Indy Component UDPClient, XE5 says SendBuffer cannot be called with these arguments. Will someone please help me. Here is sample code snippet:
var
i: integer;
begin
i := bpt;
if i <> 0
begin
//send Reset byte
myBuff[i] := chr(_reset); // reboot the LIA
inc(i);
IdUDPClient1.SendBuffer(myBuff,i);
end;
end;
where myBuff : array[0..255] of char;
Thank you in advance for your help.
Mike
回答1:
You need to convert your data to a TIdBytes
, which is a dynamic array of bytes. You also have to take into account that Char
is now 2 bytes in size, so if you need to remain compatible with an existing app, use AnsiChar
or Byte
instead of Char
:
var
myBuff: array[0..255] of Byte;
...
var
i: integer;
begin
i := bpt;
if i <> 0 then
begin
//send Reset byte
myBuff[i] := _reset; // reboot the LIA
inc(i);
IdUDPClient1.SendBuffer(RawToBytes(myBuff[0],I));
end;
end;
Or:
var
myBuff: TIdBytes;
...
var
i: integer;
begin
SetLength(myBuff, 256);
...
i := bpt;
if i <> 0 then
begin
//send Reset byte
myBuff[i] := _reset; // reboot the LIA
inc(i);
IdUDPClient1.SendBuffer(myBuff);
end;
end;
来源:https://stackoverflow.com/questions/27129331/upgrading-to-xe5-from-delphi-5-udpclient-sendbuffer