L
liujiandong
Unregistered / Unconfirmed
GUEST, unregistred user!
我在使用memo控件打印收到的字符串时,明明收到的是一个定长的字符串,可
显示在memo中时,总是在字符串后面跟着一、二个乱码,不知是为什么,代码
如下:
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
MyStream: TMemoryStream;
recvchar:array[1..600] of char;
TmpStr: String;
i:integer;
begin
MyStream := TMemoryStream.Create;
try
NMUDP1.ReadStream(MyStream);
SetLength(TmpStr,NumberBytes);
MyStream.Read(TmpStr[1],NumberBytes);
fillchar(recvchar,600,#0);
for i:=1 to NumberBytes do
recvchar := TmpStr;
if recvchar[18]<>#$b6 then
begin
for i:=38 to numberbytes do
recvchar[i-37]:=tmpstr;
memo1.Lines.add(recvchar);
end;
finally
MyStream.Free;
end;
end;
显示在memo中时,总是在字符串后面跟着一、二个乱码,不知是为什么,代码
如下:
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
MyStream: TMemoryStream;
recvchar:array[1..600] of char;
TmpStr: String;
i:integer;
begin
MyStream := TMemoryStream.Create;
try
NMUDP1.ReadStream(MyStream);
SetLength(TmpStr,NumberBytes);
MyStream.Read(TmpStr[1],NumberBytes);
fillchar(recvchar,600,#0);
for i:=1 to NumberBytes do
recvchar := TmpStr;
if recvchar[18]<>#$b6 then
begin
for i:=38 to numberbytes do
recvchar[i-37]:=tmpstr;
memo1.Lines.add(recvchar);
end;
finally
MyStream.Free;
end;
end;