One simple way is to use a stringlist...
function in_file(filename : string;
text2find : string;
casesense : boolean) : boolean;
var sl : tstringlist;
begin
result := false;
sl := tstringlist.create;
try
sl.loadfromfile(filename);
if casesense
then result := (pos(text2find,sl.text) > 0)
else result := (pos(uppercase(text2find),
uppercase(sl.text)) > 0);
finally
sl.free;
end;
end;
This approach has a few limits. Most notably, it loads the entire file into memory before testing, so it might be slow on large files. If the file is very large, this method might not provide accurate results because stringlist has a capacity limit and the exception (raised by exceeding that capacity) sends the same false result value as not finding the text in a normal size file sends.
Still, it is quick to code, simple to understand and will work most of the time.
Hope it helps.
Peace,
Colt.