从Delphi 5升级到XE5:UDPClient.SendBuffer [英] Upgrading to XE5 from Delphi 5: UDPClient.SendBuffer
问题描述
我将Delphi的较旧版本升级到XE5,较旧的版本使用Indy Component UDPClient,XE5说无法使用这些参数调用SendBuffer。有人可以帮我吗。以下是示例代码段:
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;
其中myBuff:数组char [0..255];
where myBuff : array[0..255] of char;
在此先感谢您的帮助。
迈克
推荐答案
您需要将数据转换为 TIdBytes
,这是一个动态字节数组。您还必须考虑到 Char
现在的大小为2个字节,因此,如果需要保持与现有应用程序的兼容性,请使用 AnsiChar
或 Byte
代替 Char
:
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;
或:
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;
这篇关于从Delphi 5升级到XE5:UDPClient.SendBuffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!