下面是一个简单的例子,我只做了一个线程,如果要更多的线程,在窗体上添加IdThreadComponent并将OnRun关联到IdThreadComponent1Run即可。
对于在OnRun中的语句,我中是简单的写一下,请根据你的实际要求改……
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdComponent, IdTCPConnection, IdTCPClient, IdFTP,
IdBaseComponent, IdThreadComponent;
type
TForm1 = class(TForm)
IdThreadComponent1: TIdThreadComponent;
procedure IdThreadComponent1Run(Sender: TIdCustomThreadComponent);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.IdThreadComponent1Run(Sender: TIdCustomThreadComponent);
var
f: TIdFTP;
begin
f := TIdFTP.Create(Self);
try
f.Username := 'anonymous';
f.Password := 'cyd@dl99.net';
f.Host := '192.168.0.1';
f.Port := 21;
while not (Sender.Stopped or Sender.Terminated) do
try
f.Connect;
Sleep(10000);
f.Quit;
except
end;
finally
f.Free;
end;
end;
end.