文件映射对象相当有效
FileHandle:=CreateFile(PChar(FileName),
GENERIC_READ,0,Nil,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
If FileHandle<>INVALID_HANDLE_VALUE Then
begin
try
MapHandle:=CreateFileMapping(FileHandle,
Nil,PAGE_READONLY,0,0,Nil);
If MapHandle<>NULL Then
Begin
try
Log:='成功打开文件'#$0D#$0A;
Addr:=MapViewOfFile(MapHandle,FILE_MAP_READ,0,0,0);
If Addr<>Nil Then
begin
try
Log:=Log+'成功建立映射对象'#$0D#$0A;
DoWork(Addr,GetFileSize(FileHandle,Nil));
finally
If UnmapViewOfFile(Addr) Then
Log:=Log+'成功撤消文件映射'#$0D#$0A;
end;
end;
finally
CloseHandle(MapHandle);
end;
End;
finally
CloseHandle(FileHandle);
end;
end;