|
楼主 |
发表于 2020-1-18 21:45:22
|
显示全部楼层
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdTelnet;
type
TForm1 = class(TForm)
mmo1: TMemo;
btn1: TButton;
idtlnt1: TIdTelnet;
edt1: TEdit;
lbl1: TLabel;
edtIP: TEdit;
lbl2: TLabel;
lbl3: TLabel;
edtport: TEdit;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure idtlnt1DataAvailable(Sender: TIdTelnet;
const Buffer: String);
procedure btn2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i,b:Integer ;
s:string ;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
s:= Trim(edt1.Text );
for i:=1 to Length(s) do
begin
idtlnt1.SendCh(s[i]) ;
end;
idtlnt1.SendCh(#13) ;
edt1.Text := '' ;
end;
procedure TForm1.idtlnt1DataAvailable(Sender: TIdTelnet;
const Buffer: String);
begin
mmo1.Lines.Add(Buffer) ;
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
idtlnt1.Host := Trim( edtIP.Text ) ;
idtlnt1.Port := StrToInt( trim( edtport.Text ) ) ;
if not idtlnt1.Connected then
idtlnt1.Connect(2000) ;
// idtlnt1.Connect(const atimeout:Integer = 2000) ;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if idtlnt1.Connected then
idtlnt1.Disconnect ;
end;
end.
又改了下 |
|