Autor Beitrag
TimKellner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Mi 25.10.06 17:15 
Hallo liebe Community,

ich habe (mal) wieder ein Problem. Und zwar habe ein einen TTreeView-Baum der mit sich dynamisch aufbaut. Nun möchte ich jedoch einige Objekte wie Name, ID, Status, Port anhängen ich habe mich volgendermassen versucht.
TreeView1.Items[i].AddObject(Port, 'Test');

Doch leider funktioniert mein Versuch nicht. Könnte mir einer ein bisschen unter die arme greifen oder hat ein einfaches Tutorial was ich verwenden könnte.

MFG
TIm
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 25.10.06 17:24 
Moin!

Schonmal bischen umgesehen? ;) Suche in: Delphi-Forum, Delphi-Library TTREEVIEW

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Mi 25.10.06 21:27 
Ok soweit das ich objekte anhängen kann bin ich meiner meinung nach. Das Problem habe ich danke deiner Hilfe so gelöst bekommen. Doch wie bekomme ich die Werte später bei einem ausgewähltem Ast wieder heraus
Auslesen mit
ausblenden Delphi-Quelltext
1:
tserver(TreeView_List.Selected.Data).Name					


Erzeugen des Objectes
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
TServer = class(TObject)
  private
    FID: String;
    FName: String;
    FPort: String;
    FStatus: String;
    procedure SetID(const Value: String);
    procedure SetName(const Value: String);
    procedure SetPort(const Value: String);
    procedure SetStatus(const Value: String);
  public
   property ID: String read FID write SetID;
   property Name: String read FName write SetName;
   property Port: String read FPort write SetPort;
   property Status: String read FStatus write SetStatus;
  end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
 
fserver.ID := server.Strings[0];
      fserver.Port := server.Strings[1];
      fserver.Name := server.Strings[2];
      fserver.Status := server.Strings[3];
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 25.10.06 22:07 
Moin!

Was ist jetzt konkret deine Frage? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Mi 25.10.06 22:15 
Hups. Mein Problem ist wie ich die Data Objecte des ausgewählten Astes auslesen kann
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 25.10.06 22:17 
Moin!

Hast du doch schon selbst geschrieben:
user profile iconTimKellner hat folgendes geschrieben:
Auslesen mit
ausblenden Delphi-Quelltext
1:
tserver(TreeView_List.Selected.Data).Name					

:D

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Fr 27.10.06 19:46 
Ja klar nur er wirft mir eine Exception aus. "Zugriffsverletzung bei Adresse 0048A152 in Modul 'Test.exe'. Lesen von Adresse 00000008"

Deshalb vermute ich das irgendetwas in meinem code nicht stimmt. Nur was im Code falsch ist finde ich nicht herraus.


Zuletzt bearbeitet von TimKellner am Fr 27.10.06 21:13, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.10.06 21:04 
Moin!

Sieht so aus, als wenn du in .Data NIL stehen hättest. Du mußt da beim Einfügen des Nodes natürlich eine Referenz auf deine Klasseninstanz unterbringen. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Fr 27.10.06 21:14 
Was meinst du damit?

PS: Tut mir leid das ich es nicht so richtig alleine hinbekomme
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.10.06 21:18 
Moin!

Du erzeugst doch eine Instanz von TServer, die muss in .Data rein. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Fr 27.10.06 21:23 
Verstehe leider immer noch nicht was du meinst. Das ist mein jetztziger Code wo die Exception kommt. Könntest du mir zeigen wie du es meinst.

MFG
TIm

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm_Main.TreeView_listClick(Sender: TObject);
begin
showmessage(tserver(TreeView_List.Selected.Data).Name);
end;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 00:15 
Moin!

Das ist die "falsche" Stelle, hier ist klar, was passiert. "Interessant" ist die Stelle im Code, wo du die Nodes einfügst. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Sa 28.10.06 00:29 
Edit// Thema verfehlt.
In der VirtualTreeView Hilfe steht das man besser Records als Objekte zum anhängen von Daten verwenden soll.
VirtualTreeview.chm, The virtual paradigm:
Records instead classes
Basically, the idea of virtualizing the tree control and using records instead of classes were two ideas which are born nearly at the same time. It was quite clear from the very first moment that classes can never be as effective as a simple record structures (in terms of size, access speed and management). Sure, a TPersistent only needs 4 bytes more than a record (the pointer to the class' VMT), but these are still too many extra bytes if you consider that I have wrestled quite a while with myself about every byte in a tree node (and want the minimalism principle). Another point you should not underestimate is that classes as nodes would of course also mean to put node specific methods into this class too, which will be overridden at times (this is the main argument to use a class after all). This will require additional CPU cycles just to lookup access methods, to dereference etc. which in turn will cost extra time. Trees with only some 1000 nodes will never see a large difference but for big trees this is significant and Virtual Treeview has mainly been created to address high capacity tree views.

With choosing records I also gave up the VCL concept of having a tree nodes class which is responsible to manage tree nodes and is secondary to the control itself. In Virtual Treeview every access to the tree content is done via methods and properties provided by the tree control. Keep also in mind that nobody prevents you from using classes and store their references in the node's data area. It is only just so that the node (as internal management structure) is as small as possible, opening so all possibilities: from smallest memory footprint to highest comfort.


Darum rat ich dir von den Objekten abzusehen und die einfachere Variante mit Records zu benutzen. :wink:
Hier gibts ein Tutorial dazu: www.dsdt.info/tutori...tualtreeview/?page=3

MfG


Zuletzt bearbeitet von Coder am Sa 28.10.06 22:20, insgesamt 2-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 00:43 
Moin!

user profile iconCoder hat folgendes geschrieben:
In der VirtualTreeView Hilfe steht das man besser Records als Objekte zum anhängen von Daten verwenden soll.
VirtualTreeview.chm, The virtual paradigm:
Records instead classes
Trees with only some 1000 nodes will never see a large difference but for big trees this is significant and Virtual Treeview has mainly been created to address high capacity tree views.

Darum rat ich dir von den Objekten abzusehen und die einfachere Variante mir Records zu benutzen.

Und darum rate ich, sich das nochmal sehr gut zu überlegen; ich kann mir nicht vorstellen, dass records jetzt die entscheidende Lösung bringen.

@user profile iconCoder: Er hat doch keine Performance-Probleme, sondern er kriegt ja nichmal ein Objekt untergebracht. Man kann es auch übertreiben, mit dem Optimieren... ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Sa 28.10.06 00:49 
Edit// Thema verfehlt.
user profile iconNarses hat folgendes geschrieben:
Er hat doch keine Performance-Probleme, sondern er kriegt ja nichmal ein Objekt untergebracht. Man kann es auch übertreiben, mit dem Optimieren... ;)

Mit Rekords ist es aber viiiieeeel einfacher und sie sind im Sinne des Erfinders. :wink:
Naja egal. War nur ein Vorschlag.

MfG


Zuletzt bearbeitet von Coder am Sa 28.10.06 22:19, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 00:54 
Moin!

user profile iconCoder hat folgendes geschrieben:
Mit Rekords ist es aber viiiieeeel einfacher und sie sind im Sinne des Erfinders.

a) Es ist weder einfacher, noch besser; eher anders. :D
b) Möglicherweise im Sinne des VirtualTreeView-Erfinders, aber das spielt hier ja wohl eher kaum eine Rolle.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Sa 28.10.06 12:14 
ALso meinst du diesen Abschnitt? Wie muss ich diesen verbessern?


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
server.CommaText := response;
fserver.Name := server.Strings[0];
fserver.Data).Port := server.Strings[1];
fserver.Name := server.Strings[2];
fserver.Status := server.Strings[3];
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 20:31 
Moin!

Nein, ich meine den Teil im Code, wo du einen neuen Knoten ins TreeView einfügst... ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Sa 28.10.06 21:31 
So neuer versuch.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
fserver := TServer.Create;
      server := TStringList.Create;
      try
      server.CommaText := response;
      fserver.Name := server.Strings[0];
      fserver.Data).Port := server.Strings[1];
      fserver.Name := server.Strings[2];
      fserver.Status := server.Strings[3];
      finally
      server.Free;
      TreeView_List.Items.AddChild(node,fserver.Port);
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 28.10.06 21:39 
Moin!

Ja schon besser; zeig aber bitte mal noch etwas mehr "drum rum" (konkret: wie kommst du auf "node" als Parameter usw.) ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.