1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| unit uWorkerThread;
interface
uses
System.Classes, FMX.Dialogs,
{Indy}
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdExplicitTLSClientServerBase, IdFTP,
{FireDac}
FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
FireDAC.FMXUI.Wait, FireDAC.Comp.UI, FireDAC.Comp.Client, Data.DB,
FireDAC.Comp.DataSet,
{Mine}
uStatics;
type
TWorkerThread = class(TThread)
IdFTP : TIdFTP;
mySQLconn: TFDConnection;
mySQLquery: TFDQuery;
mySQLtrans: TFDTransaction;
mySQLxWaitCursor: TFDGUIxWaitCursor;
{ procedure IdFTPStatus(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: string);
procedure IdFTPWorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
procedure IdFTPWork(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
procedure IdFTPWorkEnd(ASender: TObject; AWorkMode: TWorkMode); }
private
{ Déclarations privées }
protected
procedure Execute; override;
public
procedure UpdateUI;
procedure FinishUI;
procedure MessToUI;
end;
var
i: integer;
sErr: string;
implementation
uses SysUtils, wMain;
{ TWorkerThread }
procedure TWorkerThread.Execute;
begin
mySQLconn := TFDConnection.Create(nil);
mySQLquery := TFDQuery.Create(nil);
mySQLtrans := TFDTransaction.Create(nil);
mySQLxWaitCursor := TFDGUIxWaitCursor.Create(nil);
with mySQLconn do
begin
if Connected then Connected := False;
DriverName := 'MySQL';
Transaction := mySQLtrans;
with Params do
begin
Add('Server=' + csLicHost);
Add('Database=' + csLicBase);
Add('User_Name='+ csLicUser);
Add('Password=' + csLicPass);
end;
end;
with mySQLtrans do
Connection := mySQLconn;
with mySQLquery do
begin
Connection := mySQLconn;
Transaction := mySQLtrans;
end;
with mySQLconn do
try
Connected := True;
sErr := 'Connecté';
except
sErr := 'Connexion impossible';
end;
Synchronize(MessToUI);
for i := 1 to 100 do
begin
Synchronize(UpdateUI);
end;
with mySQLconn do
if Connected then Connected := false;
mySQLxWaitCursor.Free;
mySQLtrans.Free;
mySQLquery.Free;
mySQLconn.Free;
FreeOnTerminate := true;
Synchronize(FinishUI);
end;
procedure TWorkerThread.UpdateUI;
begin
fmain.Gauge.Value := i;
end;
procedure TWorkerThread.MessToUI;
begin
showmessage(sErr);
end;
procedure TWorkerThread.FinishUI;
begin
showmessage('Close');
fMain.Close;
end;
end. |
Partager