| 
| 
 | Вопрос # 3 332/ вопрос открыт / | 
 |  Здравствуйте, эксперты!Взял кусок готового фтп клиента! все работает-отображает файлы,размер. как отобразить процесс скачивания  в Gauge1.Progress.
 Приложение:Переключить в обычный режим  var  Spisok:TStringList; i:integer;  begin If IdFTP.Connected then IdFTP.ChangeDir('/pochta'); Spisok:=TStringList.Create();IdFTP.List(Spisok,'*.*',False);  If Spisok.Count>0 ThenBeginFor i:=0 To Spisok.Count-1 DoBegin     IF IdFTP.Size(Spisok.Strings[i])<>-1 THEN  BEGIN //Application.ProcessMessages;      //Application.ProcessMessages;   //Gauge1.Progress:=0;  //Gauge1.MinValue:=0;  //Gauge1.Progress:=IdFTP.Size(Spisok.Strings[i]);    IdFTP.Get(Spisok.Strings[i],'D:netfilein' + Spisok.Strings[i],True, False  );
|  |   Вопрос задал: djemov (статус: Посетитель)Вопрос отправлен: 27 октября 2009, 18:37
 Состояние вопроса: открыт, ответов: 1.
 |  Ответ #1. Отвечает эксперт: DNK Здравствуйте, djemov!Когда-то писал программу с FTP-клиентом. В приложении кусок кода для загрузки списка файлов. А также .pas и .dfm-файлы формы отображающую процесс. Кроме того на форме отображается скорость, прошедшее время и оставшееся до конца загрузки списка файлов.
 Приложение:Переключить в обычный режим function TMainForm.Get(const Operation: string; SourceFiles, ReceiverFiles,         Information: TStrings): Integer;var  I: Integer;  t: Integer;  fs: array of integer;begin  if (SourceFiles.Count <> ReceiverFiles.Count) or     (SourceFiles.Count <> Information.Count) then begin     Result := -5;     exit;  end;  if not Connected then begin     Result := -1;     exit;  end;  with PrForm do begin    ResetDataForm;    Caption := S_FormCaption + FTPClient.Host;    Show;    OperationLabel.Caption := S_CheckGet;    AllSize := 0;    Aborted := false;    setLength(fs, SourceFiles.Count);    for i := 0 to SourceFiles.Count - 1 do begin       t := SizeFile(SourceFiles.Strings[i]);       if t >= 0 then begin          fs[i] := t;          AllSize := AllSize + t;       end else begin          if Connected then             Result := -4          else             Result := -1;          Close;          exit;       end;    end;    OperationLabel.Caption := Operation;    OperationGauge.MaxValue := AllSize;    AllSizeSText.Caption := IntToStr(AllSize);    StartTime := Now;    for i := 0 to SourceFiles.Count - 1 do begin       FileInfoLabel.Caption := Information.Strings[i];       if not DirectoryExists(ExtractFileDir(ReceiverFiles.Strings[i])) then          CreateLocalDir(ExtractFileDir(ReceiverFiles.Strings[i]));       FileGauge.MaxValue := fs[i];       try          FTPClient.TransferType := ftBinary;          FTPClient.Get(SourceFiles.Strings[i], ReceiverFiles.Strings[i], true);          SaveLog(S_SaveFile + SourceFiles.Strings[i] + S_w + ReceiverFiles.Strings[i] + '"');       except          Close;          if Aborted then            Result := -3          else            if Connected then               Result := -2            else               Result := -1;          exit;       end;       Application.ProcessMessages;       if Aborted then Break;    end;    Close;    if Aborted then      Result := -3    else      Result := 0  end;end;   unit ProgressFormUnit; interface uses  Windows, Messages, SysUtils, {Variants, }Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, Buttons, ExtCtrls, Gauges, IdBaseComponent,  IdComponent, IdTCPConnection, IdTCPClient, IdFTP, IdAntiFreezeBase,  IdAntiFreeze; type  TProgressForm = class (TForm)    AbortBtn: TBitBtn;    AllSizeSText: TStaticText;    AntiFreeze: TIdAntiFreeze;    FileGauge: TGauge;    FileInfoLabel: TLabel;    FTPClient: TIdFTP;    GuardTimer: TTimer;    OperationGauge: TGauge;    OperationLabel: TLabel;    ProgerssTimeSText: TStaticText;    RestOfTimeSText: TStaticText;    SizeTransferSText: TStaticText;    SpeedSText: TStaticText;    StaticText1: TStaticText;    StaticText2: TStaticText;    StaticText3: TStaticText;    StaticText5: TStaticText;    StaticText6: TStaticText;    StaticText7: TStaticText;    StatusSText: TStaticText;    procedure AbortBtnClick(Sender: TObject);    procedure FTPClientStatus(ASender: TObject; const AStatus: TIdStatus; const             AStatusText: String);    procedure FTPClientWork(Sender: TObject; AWorkMode: TWorkMode; const             AWorkCount: Integer);    procedure FTPClientWorkBegin(Sender: TObject; AWorkMode: TWorkMode; const             AWorkCountMax: Integer);    procedure FTPClientWorkEnd(Sender: TObject; AWorkMode: TWorkMode);    procedure GuardTimerTimer(Sender: TObject);  private    AverageSpeed: Double;    GuardCount: Integer;  public    Aborted: Boolean;    AllSize: LongInt;    StartTime: TDateTime;    procedure ResetDataForm;  end; var  ProgressForm: TProgressForm; implementation// START resource string wizard sectionresourcestring  SProgressFormUnit_Time = '%2d:%2d:%2d';  SProgressFormUnit_Speed = '0.00 KB/s'; // END resource string wizard section  {$R *.dfm} {******************************** TProgressForm *********************************}procedure TProgressForm.AbortBtnClick(Sender: TObject);begin  Aborted := true;end; procedure TProgressForm.FTPClientStatus(ASender: TObject; const AStatus:         TIdStatus; const AStatusText: String);begin  //  StatusSText.Caption := AStatusText;end; procedure TProgressForm.FTPClientWork(Sender: TObject; AWorkMode: TWorkMode;         const AWorkCount: Integer);var  TotalTime: TDateTime;  H, M, Sec, MS: Word;  s: string;  DLTime: Double;begin  //  OperationGauge.Progress := OperationGauge.Progress + AWorkCount - FileGauge.Progress;  FileGauge.Progress := AWorkCount;  SizeTransferSText.Caption := IntToStr(OperationGauge.Progress);  TotalTime :=  Now - StartTime;  DecodeTime(TotalTime, H, M, Sec, MS);  s := Format(SProgressFormUnit_Time, [H, M, Sec]);  ProgerssTimeSText.Caption := s;  Sec := Sec + M * 60 + H * 3600;  DLTime := Sec + MS / 1000;  if DLTime > 0 then    AverageSpeed := (OperationGauge.Progress / 1024) / DLTime;  SpeedSText.Caption := FormatFloat(SProgressFormUnit_Speed, AverageSpeed);  if AverageSpeed > 0 then begin    Sec := Trunc(((OperationGauge.MaxValue - OperationGauge.Progress) / 1024) / AverageSpeed);    S := Format(SProgressFormUnit_Time, [Sec div 3600, (Sec div 60) mod 60, Sec mod 60]);  end  else S := '';  RestOfTimeSText.Caption := s;  inc(GuardCount);  Application.ProcessMessages;  if Aborted then FTPClient.Abort;end; procedure TProgressForm.FTPClientWorkBegin(Sender: TObject; AWorkMode:         TWorkMode; const AWorkCountMax: Integer);begin  //  if AWorkMode = wmWrite then FileGauge.MaxValue := AWorkCountMax;  FileGauge.Progress := 0;  GuardCount := 0;  GuardTimer.Enabled := true;end; procedure TProgressForm.FTPClientWorkEnd(Sender: TObject; AWorkMode: TWorkMode);begin  //  FileGauge.Progress := FileGauge.MaxValue;  GuardTimer.Enabled := false;end; procedure TProgressForm.GuardTimerTimer(Sender: TObject);begin  if GuardCount > 0 then     GuardCount := 0  else begin     GuardTimer.Enabled := false;     FTPClient.Abort;  end;end; procedure TProgressForm.ResetDataForm;begin  FileGauge.Progress := 0;  OperationGauge.Progress := 0;  AllSizeSText.Caption := '';  FileInfoLabel.Caption := '';  OperationLabel.Caption := '';  ProgerssTimeSText.Caption := '';  RestOfTimeSText.Caption := '';  SizeTransferSText.Caption := '';  SpeedSText.Caption := '';  StatusSText.Caption := '';end; end.   object ProgressForm: TProgressForm  Left = 321  Top = 214  BorderIcons = [biSystemMenu]  BorderStyle = bsDialog  Caption = 'FTP - êëèåíò'  ClientHeight = 178  ClientWidth = 371  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'MS Sans Serif'  Font.Style = []  OldCreateOrder = False  Position = poScreenCenter  PixelsPerInch = 96  TextHeight = 13  object OperationLabel: TLabel    Left = 8    Top = 8    Width = 72    Height = 13    Caption = 'OperationLabel'  end  object OperationGauge: TGauge    Left = 9    Top = 24    Width = 353    Height = 17    BackColor = clYellow    Color = clBtnFace    ForeColor = clNavy    ParentColor = False    Progress = 0  end  object FileInfoLabel: TLabel    Left = 8    Top = 48    Width = 60    Height = 13    Caption = 'FileInfoLabel'  end  object FileGauge: TGauge    Left = 9    Top = 64    Width = 353    Height = 17    BackColor = clYellow    ForeColor = clNavy    Progress = 0  end  object AbortBtn: TBitBtn    Left = 137    Top = 149    Width = 97    Height = 25    Caption = 'Îòìåíà'    TabOrder = 0    OnClick = AbortBtnClick    Kind = bkAbort  end  object StaticText1: TStaticText    Left = 8    Top = 111    Width = 105    Height = 17    AutoSize = False    BorderStyle = sbsSingle    Caption = 'Ïðîøëî
âðåìåíè:'    TabOrder = 1  end  object ProgerssTimeSText: TStaticText    Left = 111    Top = 111    Width = 74    Height = 17    AutoSize = False    BorderStyle = sbsSingle    TabOrder = 2  end  object StaticText2: TStaticText    Left = 8    Top = 126    Width = 105    Height = 17    AutoSize = False    BorderStyle = sbsSingle    Caption = 'Ñêîðîñòü:'    TabOrder = 3  end  object SpeedSText: TStaticText    Left = 111    Top = 126    Width = 74    Height = 17    AutoSize = False    BorderStyle = sbsSingle    TabOrder = 4  end  object StatusSText: TStaticText    Left = 287    Top = 126    Width = 74    Height = 17    AutoSize = False    BorderStyle = sbsSingle    TabOrder = 6  end  object StaticText5: TStaticText    Left = 8    Top = 96    Width = 105    Height = 17    AutoSize = False    BorderStyle = sbsSingle    Caption = 'Ïåðåäàíî:'    TabOrder = 7  end  object SizeTransferSText: TStaticText    Left = 111    Top = 96    Width = 74    Height = 17    AutoSize = False    BorderStyle = sbsSingle    TabOrder = 8  end  object StaticText6: TStaticText    Left = 184    Top = 96    Width = 105    Height = 17    AutoSize = False    BorderStyle = sbsSingle    Caption = 'Âñåãî íà
ïåðåäà÷ó:'    TabOrder = 9  end  object AllSizeSText: TStaticText    Left = 287    Top = 96    Width = 74    Height = 17    AutoSize = False    BorderStyle = sbsSingle    TabOrder = 10  end  object StaticText7: TStaticText    Left = 184    Top = 112    Width = 105    Height = 17    AutoSize = False    BorderStyle = sbsSingle    Caption = 'Îñòàëîñü
âðåìåíè:'    TabOrder = 11  end  object RestOfTimeSText: TStaticText    Left = 287    Top = 112    Width = 74    Height = 15    AutoSize = False    BorderStyle = sbsSingle    TabOrder = 12  end  object StaticText3: TStaticText    Left = 184    Top = 126    Width = 104    Height = 17    AutoSize = False    BorderStyle = sbsSingle    Caption =
'Ñîñòîÿíèå:'    TabOrder = 5  end  object FTPClient: TIdFTP    OnStatus = FTPClientStatus    MaxLineAction = maException    ReadTimeout = 0    OnWork = FTPClientWork    OnWorkBegin = FTPClientWorkBegin    OnWorkEnd = FTPClientWorkEnd    ProxySettings.ProxyType = fpcmNone    ProxySettings.Port = 0    Left = 8    Top = 149  end  object AntiFreeze: TIdAntiFreeze    Left = 40    Top = 149  end  object GuardTimer: TTimer    Enabled = False    Interval = 30000    OnTimer = GuardTimerTimer    Left = 76    Top = 149  endend *)   
|  | Ответ отправил: DNK (статус: Студент)Время отправки: 28 октября 2009, 08:24
 
 |  
 Мини-форум вопросаВсего сообщений: 2; последнее сообщение — 4 марта 2010, 11:51; участников в обсуждении: 1. 
|   | DNK (статус: Студент), 28 октября 2009, 09:16 [#1]:Примечание к ответу: Форма, отображающая процесс загрузки, не модальная. Прежде чем вызывать процедуру для главной формы надо сделать Enabled := false, а после отработки Enabled := true. Я тогда только начинал работать с Delphi и выкручивался как мог, а потом переделывать что работает не стал.
 "Digital Networked Knight" |  
|   | DNK (статус: Студент), 4 марта 2010, 11:51 [#2]:Поскольку появились люди, которым этот вопрос стал интересен, собираюсь сделать статью. 
 Пока скриншот окна:
 
 
 
   "Digital Networked Knight" |  Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте. |