Die Telnetverbindung soll aber den ganzen Programmablauf über geöffnet sein.
Solange dies der Fall ist hängt das Formular.
Hier der ganze Code:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
Telnet := TTelnetThread.create;
Telnet.SetVars('xtain.net', 3118);
Telnet.Resume;
//Telnet.Disconnect;
//Telnet.Resume;
end;
Der Thread:
Delphi-Quellcode:
UNIT mTTelnetThread;
interface
uses
classes,
sysUtils,
windows,
Dialogs,
IdBaseComponent,
IdComponent,
IdTCPConnection,
IdTCPClient,
IdTelnet;
type
TTelnetThread =
CLASS(TThread)
private
IdTelnet1: TIdTelnet;
Host:
String;
Port: Integer;
protected
procedure execute;
override;
public
constructor create;
virtual;
procedure Disconnect;
virtual;
procedure Send(Value:
String);
virtual;
procedure SetVars(fHost:
String; fPort: Integer);
virtual;
end;
implementation
constructor TTelnetThread.create;
begin
inherited create(true);
freeOnTerminate := true;
IdTelnet1 := TIdTelnet.Create(
nil);
end;
procedure TTelnetThread.execute;
begin
IdTelnet1.Host := Host;
IdTelnet1.Port := Port;
try
IdTelnet1.Connect();
// IsConnect := True;
except
// IsConnect := False;
end;
end;
procedure TTelnetThread.Send(Value:
String);
begin
IdTelnet1.WriteLn(Value);
end;
procedure TTelnetThread.SetVars(fHost:
String; fPort: Integer);
begin
Host := fHost;
Port := fPort;
end;
procedure TTelnetThread.Disconnect;
begin
IdTelnet1.Disconnect();
end;
end.