这个你试试看吧
procedure TForm1.Button1Click(Sender: TObject);
var
FileStream : TFileStream;
i, iIndex : Integer;
Buff : String;
Const
STR = '01234567890123456789';
procedure CreateStream(FileName : String);
begin
FileStream := TFileStream.Create(FileName, fmCreate);
i := 1234;
FileStream.Write(i, SizeOf(Integer));
FileStream.Write(PChar(STR)^, lstrlen(STR));
FileStream.Write(i, SizeOf(Integer));
FileStream.Write(PChar(STR)^, lstrlen(STR));
FileStream.Destroy;
end;
procedure FindString(FileName, FindStr : String);
begin
FileStream := TFileStream.Create(FileName, fmOpenRead);
SetLength(Buff, FileStream.Size);
FileStream.Position := 0;
FileStream.ReadBuffer(PChar(Buff)^, FileStream.Size);
i := Pos(FindStr, Buff);
repeat
ShowMessage(IntToStr(i));
if i > 0 then
begin
iIndex := i;
Inc(i, Pos(FindStr, copy(Buff, i + Length(FindStr), Length(Buff) - i - Length(FindStr)))); if i = iIndex then Break;
end;
until (i <= 0);
FileStream.Destroy;
end;
begin
CreateStream('c:/p.dat');
FindString('c:/p.dat','23');
end;
别人的资料。