I think that is your "Form1" usage into a thread!
try some like this:
unit Unit2;
interface
uses
System.Classes,
System.SysUtils,
System.Threading,
// IdBaseComponent,
// IdComponent,
// IdTCPConnection,
// IdTCPClient,
// IdExplicitTLSClientServerBase,
IdFTP;
type
TMyProc = procedure(AValue: string) of object; // your params...
TMyThread = class(TThread)
private
FIdFTP : TIdFTP;
FProc : TMyProc;
FFileToTransfer: string;
protected
procedure Execute; override;
public
constructor Create(const ASuspended: boolean; const AFileToTransfer: string; const AProc: TMyProc);
destructor Destroy; override;
//
// etc...
end;
implementation
{ TMyThread }
constructor TMyThread.Create(const ASuspended: boolean; const AFileToTransfer: string; const AProc: TMyProc);
begin
inherited Create(ASuspended);
//
FreeOnTerminate := true;
FIdFTP := TIdFTP.Create(nil);
FProc := AProc;
FFileToTransfer := AFileToTransfer;
end;
destructor TMyThread.Destroy;
begin
FIdFTP.Free;
//
inherited;
end;
procedure TMyThread.Execute;
begin
if (FIdFTP = nil) or (FFileToTransfer='') then
exit;
//
// ... use "FIdFTP" now with your FFileToTransfer or a list of files...
{
TThread.Synchronize(nil,
procedure
begin
// update your UI here...
end);
//
// or just
if Assigned(FProc) then
FProc('hello world'); // this run in your main-thread = app!
}
end;
end.
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure MyUpdateUI(AParam: string); // your procedure... your params
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
Unit2;
procedure TForm1.MyUpdateUI(AParam: string);
begin
// what to do?
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MyThread: TMyThread;
begin
MyThread := TMyThread.Create(true, 'myfile.txt', MyUpdateUI);
MyThread.Start;
end;
end.