Как на сколько процентов скопирован файл?

21:35
http://www.delphimaster.ru/cgi-bin/forum.pl?id=1125244172&n=5
CopyFileEx [D7, WinXP]

LiqS (28.08.05 19:49)
Можете написать пример использования функции CopyFileEx ?
Как на сколько процентов скопирован файл?

Турист (28.08.05 20:09) [2]
>LiqS (28.08.05 19:49)
http://www.delphikingdom.com/asp/answer.asp?IDAnswer=2133


--------------------------------------------------------------------------------
Джо © (28.08.05 21:17) [3]
Когда-то уже сюда постил.

unit Unit2;
 
interface
uses Windows, SysUtils, Classes, ComCtrls;
 
type
IFileCopier = interface
['{9ACEC816-5A3F-4BA4-95A2-B3C8CE08B82D}']
procedure Copy;
procedure SetProgressBar (const AProgressBar: TProgressBar);
property ProgressBar: TProgressBar write SetProgressBar;
end;
 
TFileCopier = class (TInterfacedObject, IFileCopier)
private
FSource,
FDest: string;
FProgressBar: TProgressBar;
procedure SetPosition (APos: Int64);
public
constructor Create (const ASource, ADest: string);
procedure Copy;
procedure SetProgressBar (const AProgressBar: TProgressBar);
end;
 
implementation
 
function CopyCallBack (
TotalFileSize,
TotalBytesTransferred,
StreamSize,
StreamBytesTransferred: Int64;
StreamNumber,
CallBackReasom: DWORD;
SrcFile,
DestFile: THandle;
FileCopier: TFileCopier): DWORD; stdcall;
begin
FileCopier.SetPosition(TotalBytesTransferred);
end;
 
{ TFileCopier }
 
procedure TFileCopier.Copy;
function FileSize (const AFileName: string): Int64;
var
FS: TFileStream;
begin
FS := TFileStream.Create(AFileName,fmOpenRead);
try
Result := FS.Size
finally
FS.Free;
end;
end;
begin
if Assigned(FProgressBar) then
begin
FProgressBar.Position := 0;
FProgressBar.Min := 0;
FProgressBar.Max := FileSize (FSource)
end;
if not CopyFileEx(PChar(FSource),PChar(FDest),@CopyCallback,Self,PBOOL(False),0) then
RaiseLastOSError;
end;
 
constructor TFileCopier.Create(const ASource, ADest: string);
begin
FSource := ASource;
FDest := ADest;
end;
 
procedure TFileCopier.SetPosition(APos: Int64);
begin
if Assigned (FProgressBar) then
FProgressBar.Position := APos
end;
 
procedure TFileCopier.SetProgressBar(const AProgressBar: TProgressBar);
begin
FProgressBar := AProgressBar;
if Assigned (FProgressBar) then
FProgressBar.Position := 0;
end;
 
end.


Использование:


procedure TForm1.Button1Click(Sender: TObject);
var
FileCopier: IFileCopier;
begin
FileCopier := TFileCopier.Create('I:\pub\video\movies\First_films.avi','e:\temp\film.avi');
FileCopier.ProgressBar := ProgressBar1;
FileCopier.Copy;
end;


http://www.delphimaster.ru/cgi-bin/forum.pl?id=1125244172&n=5