Autor Beitrag
McFarlane
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

WIN XP Prof.
Delphi 2005 PE, Turbo Delphi 2006, PHP (Eclipse)
BeitragVerfasst: Fr 24.11.06 17:35 
Moin,
ich hab ne Zugriffsverletzung bei:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Tcateg.delClick(Sender: TObject);
begin

tempbox.Items.Destroy;
catlist.CopySelection(tempbox);

ini := Tinifile.Create(ExtractFilePath(application.ExeName) + 'config.ini');try
  ini.DeleteKey('kategorien',tempbox.Items.Strings[0]);
finally
  ini.free;
end;


-die ini-datei existiert
-die ini variable ist initialisiert
-die selbe zeile klappt an 4 anderen stellen

Warum hier nicht???
Plz, help.
Danke, McFarlane

_________________
21 ist nur die halbe Wahrheit...
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Fr 24.11.06 17:58 
user profile iconMcFarlane hat folgendes geschrieben:
-die ini variable ist initialisiert

Warum das denn? Sie wird doch erst mit Create initialisiert???
McFarlane Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

WIN XP Prof.
Delphi 2005 PE, Turbo Delphi 2006, PHP (Eclipse)
BeitragVerfasst: Sa 25.11.06 17:57 
Ich meine damit eher das

var ini:Tinifile;

und free ist ini beim vor dem erreichen dieser stelle auch schon.
Weiß hier echt niemand ne Lösung?

_________________
21 ist nur die halbe Wahrheit...
Nam
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 24



BeitragVerfasst: Sa 25.11.06 18:22 
Also ich sehe da keinen "richtigen" Fehler. Die ini Variable nutzt du Lokal, also deklariere sie auch Lokal. Wenn du es Global machst, dann könnte es zu Problemen kommen. Eventuell benutzt du diese variable noch in einer zweiten Prozedur und hast sie bereits dort initialisiert. Das könnte der Fehler sein. Also füge

var
ini: TIniFile;

in die Prozedur.

Einthällt

tempbox.Items.Strings[0]);

einen Wert? Bist du sicher? Es könnte sein, daß der Fehler nicht ini ist, sondert ein leerer Item. Benutze eine Stringvariable und guck wo der fehler ist.

s := tempbox.Items.Strings[0]);

ini.DeleteKey('kategorien',s);
McFarlane Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

WIN XP Prof.
Delphi 2005 PE, Turbo Delphi 2006, PHP (Eclipse)
BeitragVerfasst: Sa 25.11.06 19:38 
Ich werd das mit der lokalen Definition mal testen.
An der tempbox kann es nicht liegen, da das Programm genau an der markierten Stelle crasht.

Edit: Hab es mal lokal probiert: Selber fehler....

_________________
21 ist nur die halbe Wahrheit...
McFarlane Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

WIN XP Prof.
Delphi 2005 PE, Turbo Delphi 2006, PHP (Eclipse)
BeitragVerfasst: Sa 25.11.06 19:52 
Es lag an:

tempbox.items.destroy;

wenn ich das auskommentiere, geht es zwar weiter, aber funktioniert halt nicht.
Kann mir jemand sagen wie ich alle items aus tempbox lösche?

tempbox.selectall;
tempbox.deleteselected;
klappt nicht...

Edit:
Klappt jetzt alles :D
Aber trotzdem, warum funktioneiert tempbox.items.destroy nicht?

_________________
21 ist nur die halbe Wahrheit...
Nam
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 24



BeitragVerfasst: Sa 25.11.06 20:17 
Was ist TempBox? Kenne ich nicht.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 25.11.06 20:27 
Vermutlich eine TListBox. Destroy leert die Listbox nicht, sondern gibt sie frei, d.h. du kannst nicht mehr auf sie zugreifen. Beispiel: Du hast eine Tafel, auf der verschiedene Sachen stehen. Mit Tafel.Destroy; säuberst du die Tafel nicht, sondern zerstört sie (wie der Name schon sagt) und kannst nicht mehr darauf schreiben. Mit Tafel.Clear säuberst du sie.

Löschen geht so:
ausblenden Delphi-Quelltext
1:
TempBox.Clear					

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)