C
copyyour
Unregistered / Unconfirmed
GUEST, unregistred user!
看了一个简单的Telnet客户端,为indy telnet控件编写,目前想改进一下为输入命令后,服务器端返回数据到memo1中,由于服务器端返回的数据是持续不断的,所以想在一个edit框中只显示最新收到的一行返回字符串,如果有新的就立即又显示最新的,不知道该怎样做呢?谢谢各位大哥
目前memo1获取数据方法为如下:
procedure TfrmTelnetDemo.IdTelnetDemoDataAvailable(Sender: TIdTelnet;
const Buffer: String);
const
CR = #13;
LF = #10;
var
Start, Stop : Integer;
begin
if Memo1.Lines.Count = 0 then
Memo1.Lines.Add('');
Start := 1;
Stop := Pos(CR, Buffer);
if Stop = 0 then
Stop := Length(Buffer) + 1;
while Start <= Length(Buffer) do begin
Memo1.Lines.Strings[Memo1.Lines.Count - 1] :=
Memo1.Lines.Strings[Memo1.Lines.Count - 1] +
Copy(Buffer, Start, Stop - Start);
if Buffer[Stop] = CR then begin
Memo1.Lines.Add('');
{$IFNDEF Linux}
SendMessage(Memo1.Handle, WM_KEYDOWN, VK_UP, 1);
{$ENDIF}
end;
Start := Stop + 1;
if Start > Length(Buffer) then
Break;
if Buffer[Start] = LF then
Start := Start + 1;
Stop := Start;
while (Buffer[Stop] <> CR) and (Stop <= Length(Buffer)) do
Stop := Stop + 1;
end;
end;
目前memo1获取数据方法为如下:
procedure TfrmTelnetDemo.IdTelnetDemoDataAvailable(Sender: TIdTelnet;
const Buffer: String);
const
CR = #13;
LF = #10;
var
Start, Stop : Integer;
begin
if Memo1.Lines.Count = 0 then
Memo1.Lines.Add('');
Start := 1;
Stop := Pos(CR, Buffer);
if Stop = 0 then
Stop := Length(Buffer) + 1;
while Start <= Length(Buffer) do begin
Memo1.Lines.Strings[Memo1.Lines.Count - 1] :=
Memo1.Lines.Strings[Memo1.Lines.Count - 1] +
Copy(Buffer, Start, Stop - Start);
if Buffer[Stop] = CR then begin
Memo1.Lines.Add('');
{$IFNDEF Linux}
SendMessage(Memo1.Handle, WM_KEYDOWN, VK_UP, 1);
{$ENDIF}
end;
Start := Stop + 1;
if Start > Length(Buffer) then
Break;
if Buffer[Start] = LF then
Start := Start + 1;
Stop := Start;
while (Buffer[Stop] <> CR) and (Stop <= Length(Buffer)) do
Stop := Stop + 1;
end;
end;