Upgrading to XE5 from Delphi 5: UDPClient.SendBuffer

。_饼干妹妹 提交于 2019-12-08 09:14:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!