Autor Beitrag
Sidi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47


Delphi XE5 Prof.
BeitragVerfasst: Sa 19.01.08 23:21 
Hallo zusammen,

wenn ich einem Baumknoten Daten anhängen will mache ich das wie folgt:


ausblenden Delphi-Quelltext
1:
2:
3:
  New(Node_Info);
  Node_Info^.categories_id := 0;
  ActualTreeNode := Kategorien_TreeView.Items.AddObject(nil,'[Shop]',Node_Info);


und beim schließen des Formulars den Speicher wieder freigeben möchte:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  for i := 0 to Kategorien_TreeView.Items.Count - 1 do
  if Kategorien_TreeView.Items.Item[i].Data <> nil then
  begin
    TObject(Kategorien_TreeView.Items.Item[i].Data).Free;
  end;
  Kategorien_TreeView.Items.Clear;


bekomme ich bei TObject eine Zugriffsverletzung auf Speicher xyz, weiß da jemand Rat??

Gruß
Sidi

Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 20.01.08 00:29 
Ja, weiß jemand ;)

New erstellt kein TObject, sondern reserviert nur Speicher.

Wie man in der Hilfe auch fein säuberlich erklärt finden würde, ist das Gegenstück zu New Dispose:

ausblenden Delphi-Quelltext
1:
Dispose(Kategorien_TreeView.Items.Item[i].Data);					

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Sidi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47


Delphi XE5 Prof.
BeitragVerfasst: So 20.01.08 12:30 
Super, Danke -

hab mir da die Infos in den Foren zusammengesucht und wohl was durcheinander gebracht :P


bezüglich Hilfe in Delphi, bin von Delphi 6 auf Delphi 2007 umgestiegen und muß sagen die Hilfe in Delphi 6 war wesentlich besser.

Gruß
Sidi