Z
zbsfg
Unregistered / Unconfirmed
GUEST, unregistred user!
下面的代码是Delphi 5开发人员指南中的一段,在Windows2000下正常,在
Windows98下却会出内存错误
procedure TMainForm.btnSearchClick(Sender: TObject);
var
MemMapFile: TMemMapFile;
SearchRec: TSearchRec;
RetVal: Integer;
FoundStr: PChar;
FName: String;
FindString: String;
WordCount: Integer;
begin
memFileText.Lines.Clear;
btnFindNext.Enabled := False;
lbFilesFound.Items.Clear;
RetVal := FindFirst(dlbDirectories.Directory+'/*.txt', faAnyFile, SearchRec);
try
while RetVal = 0 do
begin
FName := SearchRec.Name;
MemMapFile := TMemMapFile.Create(FName, fmOpenRead, 0, True);
try
FindString := edtSearchString.Text;
WordCount := 0; // Initialize the WordCount to zero
//就是下面这句在2000和NT中正常,在98中出错
FoundStr := StrPos(PChar(MemMapFile.Data), PChar(FindString));
if FoundStr <> nil then
begin
//找到
end;
RetVal := FindNext(SearchRec);
finally
MemMapFile.Free; { Free the memory mapped file instance }
end;
end;
finally
FindClose(SearchRec);
end;
end;
Windows98下却会出内存错误
procedure TMainForm.btnSearchClick(Sender: TObject);
var
MemMapFile: TMemMapFile;
SearchRec: TSearchRec;
RetVal: Integer;
FoundStr: PChar;
FName: String;
FindString: String;
WordCount: Integer;
begin
memFileText.Lines.Clear;
btnFindNext.Enabled := False;
lbFilesFound.Items.Clear;
RetVal := FindFirst(dlbDirectories.Directory+'/*.txt', faAnyFile, SearchRec);
try
while RetVal = 0 do
begin
FName := SearchRec.Name;
MemMapFile := TMemMapFile.Create(FName, fmOpenRead, 0, True);
try
FindString := edtSearchString.Text;
WordCount := 0; // Initialize the WordCount to zero
//就是下面这句在2000和NT中正常,在98中出错
FoundStr := StrPos(PChar(MemMapFile.Data), PChar(FindString));
if FoundStr <> nil then
begin
//找到
end;
RetVal := FindNext(SearchRec);
finally
MemMapFile.Free; { Free the memory mapped file instance }
end;
end;
finally
FindClose(SearchRec);
end;
end;