AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein why crashes the find function if a file is writeprotected ?
Thema durchsuchen
Ansicht
Themen-Optionen

why crashes the find function if a file is writeprotected ?

Ein Thema von cdkiller · begonnen am 25. Jul 2004 · letzter Beitrag vom 25. Jul 2004
Antwort Antwort
cdkiller

Registriert seit: 23. Jul 2004
23 Beiträge
 
#1

why crashes the find function if a file is writeprotected ?

  Alt 25. Jul 2004, 16:02
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;
  Mit Zitat antworten Zitat
Benutzerbild von mischerr
mischerr

Registriert seit: 6. Feb 2004
Ort: Konz
238 Beiträge
 
Delphi 10.3 Rio
 
#2

Re: why crashes the find function if a file is writeprotecte

  Alt 25. Jul 2004, 16:05
Try to change "fmopenreadwrite" to "fmOpenRead".

Regards!
  Mit Zitat antworten Zitat
cdkiller

Registriert seit: 23. Jul 2004
23 Beiträge
 
#3

Re: why crashes the find function if a file is writeprotecte

  Alt 25. Jul 2004, 16:06
oh yes

ok thanks

i think first i must drink a tee
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz