Einzelnen Beitrag anzeigen

DevilsCamp
(Gast)

n/a Beiträge
 
#1

Problem mit StrPos/AnsiStrPos

  Alt 3. Dez 2005, 09:20
ich habe folgenden Code:

Delphi-Quellcode:
Procedure ReadSection(const Section: String; List: TStrings);
var
  p : PChar;
  f : PChar;
  g : PChar;
  s : String;
begin
  List.Clear;
  f := FStream.Memory;
  f[FStream.Size] := #0;
  p := StrPos(f, PChar(Format('[%s]', [Section])+#13#10));

  if (p<>nil) then
  begin
    f := StrPos(p, PChar(#13#10+'['));

    if (f=nil) then
      f := p+StrLen(p)-2;

    try
      GetMem(g, StrLen(p)+2);
      StrLCopy(g, p, f-p);

      p := StrPos(g, PChar(']'+#13#10))+3;
      f := p;
      p := StrPos(f, PChar('='));

      while (p<>nil) do
      begin
        SetString(s, f, p-f);
        List.Add(s);
        f := StrPos(p, Pchar(#13#10))+2;
        p := StrPos(f, PChar('='));
      end;

    finally
      FreeMem(g);
    end;
  end; // if (p<>nil)

end;
Dieser Code funktioniert so wie er soll, bis zu den Zeilen
Delphi-Quellcode:
p := StrPos(g, PChar(']'+#13#10))+3;
f := p;
p := StrPos(f, PChar('='));
Da bekomme ich dann eine "Access Violation" bei
p := StrPos(f, PChar('=')); die sich völlig meines Verständnisses entzieht.

Bei debuggen sehe ich auch, dass vor dieser Zeile f WIRKLICH gleich p ist und auch Text vorhanden ist (f und p sind NIChT nil und die Länge ist > 0)

Vielleicht kann mir einer helfen




PS:
Ich habe es auch schon AnsiStrPos statt StrPos versucht.
  Mit Zitat antworten Zitat