//这是我用文件影射写的,凭记忆写的,稍做修改就可以用了
procedure searchText(FRname,FSname:String);
var
FRFileHandle,FSFileHandle:THandle; //文件内核句柄
FRMapHandle,FSMapHandle:THandle; //文件影射句柄
FRFilesize,FSFileSize,SLen,Rlen:integer;
PRData,FSData
char; //文件视图的地址
Sbuf,Rbuf:array[0..255]of char;
begin
FRFileHandle:=FileOpen(FRName,fmOpenRead);
if FRFileHandle=INVALID_HANDLE_VALUE then
raise Exception.Create('打开文件错误!');
try
FRFileSize:=GetFileSize(FRFileHandle,Nil);
FMapHandle:=CreateFileMapping(FRFileHandle,
nil,
PAGE_READONLY,
0,
FRFileSize,
nil
);
if FRMapHandle=0 then
raise Exception.Create('创建文件内存影射对象错误!');
finally
CloseHandle(FRFileHandle);
end;
FSFileHandle:=FileOpen(FSName,fmOpenRead);
if FSFileHandle=INVALID_HANDLE_VALUE then
raise Exception.Create('打开文件错误!');
try
FSFileSize:=GetFileSize(FSFileHandle,Nil);
FSMapHandle:=CreateFileMapping(FSFileHandle,
nil,
PAGE_READONLY,
0,
FSFileSize,
nil
);
if FSMapHandle=0 then
raise Exception.Create('创建文件内存影射对象错误!');
finally
CloseHandle(FSFileHandle);
end;
try
PRData:=MapViewOfFile(FRMapHandle,FILE_MAP_READ,
0,0,FFileSize);
if PData=Nil then
Raise Exception.Create('创建影射视图出错!');
finally
CloseHandle(FRMapHandle);
end;
//最好用个进度条
i:=0;
j:=0;
while i<FRFileSize do
while j<FSFileSize do
begin
FillChar(Rbuf,sizeof(Rbuf),i);
FillChar(Sbuf,sizeof(Sbuf),0);
if i+256<FRfielsize then
RLen=256
else RLen=FRfilesize-i;
if j+256<FSfielsize then
Slen=256
else RLen=FRfilesize-i;
inc(i,Rlen);
inc(j,Slen);
CopyMemory(@Rbuf,PRData,i);
CopyMemory(@Sbuf,PSData,j);
//在这里,你进行比较
end;
UnmapViewOfFile(PRData);
UnmapViewOfFile(PSData);
end;