![]() |
Problem mit StrPos/AnsiStrPos
ich habe folgenden Code:
Delphi-Quellcode:
Dieser Code funktioniert so wie er soll, bis zu den Zeilen
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;
Delphi-Quellcode:
Da bekomme ich dann eine "Access Violation" bei
p := StrPos(g, PChar(']'+#13#10))+3;
f := p; p := StrPos(f, PChar('='));
Delphi-Quellcode:
die sich völlig meines Verständnisses entzieht.
p := StrPos(f, PChar('='));
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. |
Re: Problem mit StrPos/AnsiStrPos
Ich habe folgendes Herausgefunden:
Wenn ich
Delphi-Quellcode:
benutze, dann bekomme ich die Access Violation.
p := StrPos(f, PChar('='));
Benutze ich aber:
Delphi-Quellcode:
oder
s := '=';
p := StrPos(f, PChar(s));
Delphi-Quellcode:
dann kommt sie nicht
p := StrPos(f, PChar('aa')); // oder irgendeinen anderen String mit MINDESTENS 2 Zeichen
<edit> Habe 'ne möglichkeit gefunden:
Delphi-Quellcode:
</edit>
p := StrPos(f, '='#0);
|
Re: Problem mit StrPos/AnsiStrPos
Und so ging es nicht? (die CompilerMagic sollte es möglich machen)
Delphi-Quellcode:
Die #0 ist ja sonst auch mit im String drin, auch wenn man diese nicht sieht ^^
p := StrPos(f, '=');
|
Re: Problem mit StrPos/AnsiStrPos
:wall: :wall: :wall:
Auf die einfachste Lösung kommt man meistens nie selber :D |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:15 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