Autor Beitrag
MightyPit
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 22

Win XP
Delphi 2005 pro, Delphi 7
BeitragVerfasst: Mi 17.01.07 12:15 
hallo Community,

Ich hab ein sehr seltsames Phenomen, vielleicht weiß jemand von euch Rat.

Ich versuche mich an einem Dateiparser, und im folgenden Seht ihr den Code für meine Wort-Parse Routine. isSeparator prüft ob das eingelesene Zeichen ein lf, cr, tab, komma oder space ist.
Das geht ne ganze weile gut, aber dann komm ich an eine stelle an der ich den string "1.75" vom stream lesen will. bis "1." klappt es, und beim versuch die "7" an den string zu hängen
ausblenden Delphi-Quelltext
1:
      result := result + c;					

kachelt es :( Kann sich jemand darauf einen reim machen?
Danke schonmal,
Peter

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
function nextWord(aStream : TStream; moveOn : boolean = true) : string;
var c : Char;
    savePos, savePos2 : integer;
    finish : boolean;
    s : string;
begin
  result := '';
  setlength(result, 0);
  if not moveOn then
    savePos := aStream.Position;
  finish := false;
  while (length(result) = 0) or not finish do
  begin
    aStream.Read(c,1);
    finish := false;
    if c = '#' then  // Rest der Zeile ist Kommentar
    begin
      readLn(aStream, s);
      finish := true;
    end;
    if isSeparator(c) then
      finish := true;
    if not finish then
    begin
      result := result + c;
    end;
    if (result = '{') or (result = '}') or (result = '[') or (result = ']') then
      finish := true;
    //Wort ohne space zwischen Klammer
    savePos2 := aStream.Position;
    aStream.Read(c,1);
    if (c = '}') or (c = ']') then
      finish := true;
    aStream.Position := savePos2;
  end;
  if not moveOn then
    aStream.Position := savePos;
end;
oldmax
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 380


D3 Prof, D4 Prof
BeitragVerfasst: Mi 17.01.07 12:59 
Hi
Auch wenn's vielleicht blöd klingt, aber versuch mal statt

ausblenden Delphi-Quelltext
1:
var c : Char;					


diese Deklaration
ausblenden Delphi-Quelltext
1:
var c : String[1];					


oder einfach nur
ausblenden Delphi-Quelltext
1:
var c : String[1];					


String und Char mögen sich irgendwie nicht...
Gruß oldmax

_________________
Zier dich nich so, ich krieg dich schon....
MightyPit Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 22

Win XP
Delphi 2005 pro, Delphi 7
BeitragVerfasst: Mi 17.01.07 14:29 
So, danke für deine Antwort, das wars nicht :)
Ich las ja die ganze Zeit schon Wörter so raus.
Ich hab das Problem aber jetzt gefunden. In der Routine die dieses nextWord aufruft, schrieb ich eine Zeile vorher auf einen nicht allokierten Speicherbereich.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
setlength(dynarray,0);
i := 0;
while not irgendwas do
begin
  inc(i)
  setlength(dynarray, length(dynarray)+1);
  dynarray[i] := gibwert(blub); //  <- schreibt auf speicherplatz im dynarray der noch nicht allokiert ist.
  actualword := nextWord(astream);
end;


aber das hab ich behoben. Danke nochmal für den versuch ;)