![]() |
why crashes the find function if a file is writeprotected ?
hello,
i have a little question. why crashes these find in file function when a file is writeprotected ? i will not change datas i will oly search in it. can someone give me the changes which i must do that the function will read writeprotected files ? thansks...
Delphi-Quellcode:
function FindInFile(const FileName : string;
SearchWord : string; MatchCase : Boolean) : Integer; var fs : TFileStream; Buffer : array [1..10000] of Char; Size : Integer; idx : Integer; i : Integer; begin Result := -1; idx := 1; if not MatchCase then SearchWord := UpperCase(SearchWord); fs := TFileStream.Create(FileName, fmopenreadwrite or fmsharedenynone); try Repeat Application.ProcessMessages; Size := (Fs.Size - Fs.Position); if Size > 10000 then Size := 10000; Fs.ReadBuffer(Buffer, Size); if not MatchCase then begin for i := 1 to Size do Buffer[i] := Uppercase(Buffer)[i]; end; for i := 1 to Size do begin if (Buffer[i] = SearchWord[idx]) then Inc(idx) else idx := 1; if (idx = Length(SearchWord)+1) then begin Result := (fs.Position - Size) + i - idx + 1; Exit; end; end; until fs.Position >= fs.Size; finally fs.Free; end; end; |
Re: why crashes the find function if a file is writeprotecte
Try to change "fmopenreadwrite" to "fmOpenRead".
Regards! |
Re: why crashes the find function if a file is writeprotecte
oh yes :wall: :wall: :wall:
ok thanks i think first i must drink a tee :mrgreen: :thuimb: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:46 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz