procedure TForm1.Button1Click(Sender: TObject);
var
FH,MH,DH1,DH2,DH3:THandle;
YSize,I,J,AAA,BBB
Word;
P1,P2,P3,P4:^Byte;
begin
if not FileExists('G:/delphi7/delphi7.rar') then
raise Exception.Create('文件没找到!!')
else
FH:=FileOpen('G:/delphi7/delphi7.rar',fmOpenRead);
YSize:=GetFileSize(FH,nil);
MH:=CreateFileMapping(FH,nil,Page_ReadOnly,0,Ysize,nil);
CloseHandle(FH);
P1:=MapViewOfFile(MH,File_Map_Read,0,0,YSize);
P3:=P1;
CloseHandle(MH);
//建立影像
DH1:=FileCreate('A.rar');
FileClose(DH1);
DH1:=FileOpen('A.rar',fmOpenreadWrite);
DH2:=CreateFileMapping(DH1,nil,Page_ReadWrite,0,YSize,nil);
CloseHandle(DH1);
P2:=MapViewOfFile(DH2,File_Map_All_Access,0,0,YSize);
CloseHandle(DH2);
P4:=P2;
ProgressBar1.Max:=YSize;
J:=0;
AAA:=GetTickCount();
For I:=1 to YSize do
begin
P2^:=P1^;
INC(P1);
INC(P2);
Inc(J);
IF J=300000 then
begin
ProgressBar1.Position:=I;
J:=0;
end;
end;
ProgressBar1.Position:=YSize;
BBB:=(GetTickCount()-AAA) div 1000;
Label1.Caption:=InttoStr(BBB);
UnMapViewOfFile(P3);
UnMapViewOfFile(P4);
end;
这是我自己拷贝文件测试用的,改成多线程很简单的。