Bonjour à tous.
J'utilise Delphi 6 et j'ai deux problèmes à vous soumettre :
Mon logiciel doit pouvoir télécharger des fichiers; l'adresse URL source et le répertoire de sauvegarde cible sont contenus dans une base de données Access 2000.
J'ai une boucle qui lance le téléchargement de chaque fichier l'un après l'autre et tout fonctionne.
MAIS (car il y a toujours un mais...)
1. J'ai un bouton pour mettre en pause qui est fonctionnel; un pour annuler toute l'opération qui fonctionne aussi; mais je cherche à pouvoir aussi annuler uniquement l'item courant de la boucle...
2. J'ignore complètement comment gérer les cas d'erreurs et je ne trouve pas de DocURL introuvable, serveur occupé, délai trop long, etc...
Voici le code (moins tout l'affichage et les multiples conditionnels) :
Si vous pouvez m'orienter dans la bonne direction, je serais déjà très heureux :-)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 procedure TmInst.LaunchInstallation(Sender: TObject); var x, y, k2: Integer; begin DataM.AppCmd.First; for y:= 0 to DataM.AppCmd.RecordCount- 1 do begin ItemCmd:= ''; ItemParam:= ''; RunDownloadCommand(Sender); Sleep(100); DataM.AppCmd.Next; end; end; procedure TmInst.Button1Click(Sender: TObject); begin ShowMessage('Job Paused ! Press OK to continue.'); end; procedure TmInst.Button2Click(Sender: TObject); begin ShowMessage('Job Cancelled ! Press OK to continue.'); Application.Terminate; // HOW TO ONLY CANCEL CURRENT ITEM Y AND NOT ALL... end; procedure TmInst.RunDownloadCommand(Sender: TObject); var cc1, cc2: string; TmpFileStream: TFileStream; begin ItemCmd:= DataM.AppCmd.FieldByName('cCmd').AsString; cc2:= DataM.AppCmd.FieldByName('cSwitch').AsString; ItemParam:= DataM.ConvertBackRelativePath(cc2); try try TmpFileStream:= TFileStream.Create(ItemParam, fmCreate); IdHTTP.Get(ItemCmd, TmpFileStream); except // if IdHTTP.ClosedGracefully= True then Exit; ?? // need handling for Socket Error(s) AS #10060 'Cnx timed out' end; finally FreeAndNil(TmpFileStream); end; end; procedure TmInst.IdHTTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer); begin if AWorkMode= wmRead then begin ProgressBar2.Max:= AWorkCountMax; ProgressBar2.Position:= 0; FStartDate:= Now; end; end; procedure TmInst.IdHTTPWork(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer); var ElapsedTime: Cardinal; begin if AWorkMode= wmRead then begin ProgressBar2.Position:= AWorkCount; Label9.Caption:= Format(RS_Debit, [AWorkCount, ProgressBar2.Max]); ElapsedTime:= SecondsBetween(Now, FStartDate); if ElapsedTime> 0 then Label14.Caption:= Format('%s', [FormatFloat('0.00', (AWorkCount/1024)/ElapsedTime)]) + ' KB/sec'; Application.ProcessMessages; //Sleep(10); //--> activate to slow down download... end; end; procedure TmInst.IdHTTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode); begin if AWorkMode= wmRead then begin Label9.Caption:= RS_Fin; ProgressBar2.Position:= 0; end; end;
Si vous avez des exemples, je suis preneur aussi
Merci.
Partager