Autor Beitrag
FinalFantasy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 127

Windows XP
Delphi 5 Professional, Visual Studio 7 .NET (C#)
BeitragVerfasst: Mi 14.09.05 11:02 
Hi,

ich habe hier ein Riesenproblem!! Immer wenn der Speicher eines String, Stringlist oder ähnlichem erweitert werden muss (was ja bei beiden genannten Typen automatisch geschehen sollte), bekomm ich eine Zugriffsverletzung...
Wenn ich den Speicher jedoch manuell erweitere, dann funktioniert es.

Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var str: string;
    strlist: TStringList;

//------------------------------------------------
for i := 0 to 10 do 
  str := str + 'abc';      <-- Zugriffsverletzung
//------------------------------------------------
setlength(str, 30);
for i := 0 to 10 do 
  str := str + 'abc';      <-- keine Zugriffsverletzung

//------------------------------------------------

strlist := TStringList.Create();
strList.Add('blubb');      <-- Zugriffsverletzung
//------------------------------------------------
strlist := TStringList.Create();
strlist.capacity := 20;
strList.Add('blubb');      <-- keine Zugriffsverletzung


hat da jemand eine Erklärung dafür????

BTW: das Problem taucht anscheinend nur in meiner neuen Unit auf, und in der Verwende ich RegExpr... Was ich so gesehen habe, betätigt diese Unit einige Compilerschalter... kann es vielleicht sein, dass es daran irgendwie liegt?

Moderiert von user profile iconraziel: Titel geändert.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 14.09.05 12:06 
Das Erste kann ich Dir erklären:

Schalt mal deine Compiler-Warnungen ein, dann müsste er Dir eigentlich sowas bringen wie "Variable str wahrscheinlich nicht initialisiert" ... --> Variablen vor Benutzung initialisieren.

Warum die SL bei nem Add crasht weiß ich nicht ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
FinalFantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 127

Windows XP
Delphi 5 Professional, Visual Studio 7 .NET (C#)
BeitragVerfasst: Mi 14.09.05 12:09 
Die Warnungen habe ich aktiv... Kommt in obigem Beispiel nicht raus, sorry, aber ich habe meine Strings mit str := '' initialisiert.
Die StringList wird ja beim Create initialisiert, oder?
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 14.09.05 12:15 
Nur so nebenbei:
Str ist eine Delphi Prozedur:
Zitat:
ausblenden Delphi-Quelltext
1:
procedure Str(X [: Width [: Decimals ]]; var S);					

Bennen mal die Variable um.
FinalFantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 127

Windows XP
Delphi 5 Professional, Visual Studio 7 .NET (C#)
BeitragVerfasst: Mi 14.09.05 12:21 
Sachen gibts ;-).... Im Programm heissen die Strings anders und sind überdies mehrere, und bei alles das selbe Problem... Die StringList stört mich aber mehr als die einfachen Strings.
Ich denke rcommand, command, src, dst... sollten da keine Probleme machen
FinalFantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 127

Windows XP
Delphi 5 Professional, Visual Studio 7 .NET (C#)
BeitragVerfasst: Mi 14.09.05 13:41 
Hat sich erledigt... mir hat vorher ein FillChar wohl etwas überschrieben....