From 2599c810184636b608313ae26c99428da06e6972 Mon Sep 17 00:00:00 2001 From: Almindor <almindor@gmail.com> Date: Mon, 6 Nov 2006 21:41:22 +0000 Subject: [PATCH] + adds LocalEcho property to TLTelnetClient * fixes telnet example to do proper error reporting and lineendings git-svn-id: trunk@5267 - --- fcl/lnet/examples/ltelnet/ltclient.pp | 36 ++++++++++++++------------- fcl/lnet/ltelnet.pp | 4 ++- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/fcl/lnet/examples/ltelnet/ltclient.pp b/fcl/lnet/examples/ltelnet/ltclient.pp index 906f2ad286..25774524a2 100644 --- a/fcl/lnet/examples/ltelnet/ltclient.pp +++ b/fcl/lnet/examples/ltelnet/ltclient.pp @@ -30,6 +30,7 @@ type constructor TLTelnetTest.Create; begin FCon:=TLTelnetClient.Create(nil); + FCon.OnError:=@OnError; end; destructor TLTelnetTest.Destroy; @@ -46,9 +47,8 @@ end; procedure TLTelnetTest.Run; var - s: string; + s, SendStr: string; c: Char; - l: Longint; // length of line currently written AD: string; PORT: Word; begin @@ -63,8 +63,9 @@ begin Writeln('Usage: ', ExtractFileName(ParamStr(0)), ' IP PORT'); Exit; end; + FQuit:=False; - l:=0; + if FCon.Connect(AD, PORT) then begin Writeln('Connecting... press any key to cancel'); repeat @@ -73,27 +74,28 @@ begin if KeyPressed then Halt; until FCon.Connected; // wait until timeout or we actualy connected + + SendStr:=''; while not FQuit do begin // if we connected, do main loop if KeyPressed then begin c:=ReadKey; case c of #27: FQuit:=True; - #8: if l > 0 then - begin - GotoXY(WhereX-1, WhereY); - Write(' '); - Dec(l); - FCon.SendMessage(c); - end; - else begin - Inc(l); - if c = #13 then begin - Writeln; - l:=0; + #8: if Length(SendStr) > 0 then begin + GotoXY(WhereX-1, WhereY); + Write(' '); + GotoXY(WhereX-1, WhereY); + SetLength(SendStr, Length(SendStr) - 1); + end; + else if c = #13 then begin + Writeln; + FCon.SendMessage(SendStr + #13#10); + SendStr:=''; + end else begin + SendStr:=SendStr + c; + Write(c); end; - FCon.SendMessage(c); - end; end; end; if FCon.GetMessage(s) > 0 then diff --git a/fcl/lnet/ltelnet.pp b/fcl/lnet/ltelnet.pp index ad356e9c8d..8de4afd314 100644 --- a/fcl/lnet/ltelnet.pp +++ b/fcl/lnet/ltelnet.pp @@ -124,6 +124,7 @@ type TLTelnetClient = class(TLTelnet, ILClient) protected + FLocalEcho: Boolean; procedure OnEr(const msg: string; aSocket: TLSocket); procedure OnDs(aSocket: TLSocket); procedure OnRe(aSocket: TLSocket); @@ -139,6 +140,7 @@ type function SendMessage(const msg: string; aSocket: TLSocket = nil): Integer; override; procedure SendCommand(const aCommand: Char; const How: TLHowEnum); procedure CallAction; override; + property LocalEcho: Boolean read FLocalEcho write FLocalEcho; end; implementation @@ -424,7 +426,7 @@ begin SetLength(Tmp, aSize); Move(aData, PChar(Tmp)^, aSize); DoubleIAC(Tmp); - if (not OptionIsSet(TS_ECHO)) and (not OptionIsSet(TS_HYI)) then + if LocalEcho and (not OptionIsSet(TS_ECHO)) and (not OptionIsSet(TS_HYI)) then FOutput.Write(PChar(Tmp)^, Length(Tmp)); Result:=FConnection.SendMessage(Tmp); end;