Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi TreeView nach VirtualStringTree (https://www.delphipraxis.net/27873-treeview-nach-virtualstringtree.html)

djmasi 16. Aug 2004 21:03


TreeView nach VirtualStringTree
 
Liste der Anhänge anzeigen (Anzahl: 2)
Hallo Leute,

ich zerbrech mir hier gerade übelst den Kopf. Hab im Forum und Tutorials gesucht aber nix gefunden :cry:

Die Ausgangsstellung:

Habe eine TreeView, die ich mit Daten einer DB fülle. Das geht wunderbar.
Delphi-Quellcode:
//****************************************************************************//
//fill nodes with records from database
procedure TFMain.UpdateNodes(Node: TTreeNode; DS: TpFIBDataSet; Field: String);
var
//  DSCount: Integer;
  IsExp: Boolean;
  SQL: String;
begin
  //query of used categories
  DS.Close;
  SQL := 'select ' + Field + ' from ' + Field +', SONG ';
  SQL := SQL + 'where SONG.' + Field + '_ID = ' + Field + '.ID ';
  SQL := SQL + 'group by ' + Field + ' order by ' + Field;
  DS.SelectSQL.Clear;
  DS.SelectSQL.Add(SQL);
  DS.Open;
  DS.Last;
  DS.First;
  //formal thing
  IsExp := TVMain.Items[Node.Index].Expanded;
  //delete all children of the node and fill in new
  TVMain.Items.Item[Node.Index].DeleteChildren;
  while not DS.Eof do
  begin
    TVMain.Items.AddChild(Node, DS[Field]);
    Application.ProcessMessages;
    DS.Next;
  end;
  TVMain.Items.Item[Node.Index].Expanded := IsExp;
  Node.Text := Field + 's (' + IntToStr(DS.RecordCount) + ')';
end;
//****************************************************************************//
//****************************************************************************//
Das Problem
Das ganze möchte ich jetzt mit einem VirtualStringTree machen. Ich bin nach dem Tutorial gegangen von Mike Lischke. Es funktioniert nur, wenn ich FocusedNode benutze. Ich möchte aber die Childs einer meiner Hauptnodes erneuern (z.B. Genre)

Als erstes meine Datenstruktur:
Delphi-Quellcode:
  TBasicNodeData = class
  protected
    cImageIndex: Integer;
    cName:      ShortString;
  public
    constructor Create; overload;
    constructor Create(vName: ShortString;
                       vIIndex: Integer = 0); overload;

    property Name: ShortString read cName write cName;
    property ImageIndex: Integer read cImageIndex write cImageIndex;
  end;

  rSectionsData = record
    BasicND: TBasicNodeData;
  end;

var
  FMain: TFMain;
  ndLibrary,
  ndArtist,
  ndAlbum,
  ndGenre,
  ndLanguage,
  ndPlaylist: PVirtualNode;
Die Hauptnodes erzeuge ich so
Delphi-Quellcode:
procedure TFMain.CreateSectionNode(Node: PVirtualNode;
                                   Caption: String);
var
  NodeD: ^rSectionsData;
begin
  VSTSections.NodeDataSize := SizeOf(rSectionsData);
  Node := VSTSections.AddChild(nil);
  NodeD := VSTSections.GetNodeData(Node);
  NodeD.BasicND := TBasicNodeData.Create(Caption);
end;

procedure TFMain.FormCreate(Sender: TObject);
begin
  CreateSectionNode(ndLibrary, 'Library');
  CreateSectionNode(ndArtist, 'Artists');
  CreateSectionNode(ndAlbum, 'Albums');
  CreateSectionNode(ndGenre, 'Genres');
  CreateSectionNode(ndLanguage, 'Languages');
  CreateSectionNode(ndPlaylist, 'Playlist');
end;
Die Childs werden hier erzeugt
Delphi-Quellcode:
procedure TFMain.Button1Click(Sender: TObject);
var
  NodeD: ^rSectionsData;
  Node: PVirtualNode;
begin
  DMMedia.ZQ1.First;
  while NOT DMMedia.ZQ1.Eof do
  begin
    Node := VSTSections.AddChild(ndGenre);
    NodeD := VSTSections.GetNodeData(Node);
    NodeD.BasicND := TBasicNodeData.Create(DMMedia.ZQ1Genre.AsString);
    DMMedia.ZQ1.Next;
  end;
end;
Wenn ich statt ndGenre FocusedNode einsetze funktioniert es, aber halt nicht dort wo ich will :wall:

djmasi 16. Aug 2004 21:37

Re: TreeView nach VirtualStringTree
 
:cheers: Ich glaub ich sollte öfters mal ein Glas Wein trinken :mrgreen:

Hab doch glatt übersehen dass den PVirtualNodes garnix zugewiesen wird. Hab aus der procedure ne function gemacht und siehe da es geht

Also hier mal die function:
Delphi-Quellcode:
function TFMain.CreateSectionNode(Node: PVirtualNode;
                                  Caption: String): PVirtualNode;
var
  NodeD: ^rSectionsData;
begin
  VSTSections.NodeDataSize := SizeOf(rSectionsData);
  Result := VSTSections.AddChild(Node);
  NodeD := VSTSections.GetNodeData(Result);
  NodeD.BasicND := TBasicNodeData.Create(Caption);
end;
So aufzurufen:
Delphi-Quellcode:
procedure TFMain.FormCreate(Sender: TObject);
begin
  ndLibrary := CreateSectionNode(nil, 'Library');
  ndArtist := CreateSectionNode(nil, 'Artists');
  ndAlbum := CreateSectionNode(nil, 'Albums');
  ndGenre := CreateSectionNode(nil, 'Genres');
  ndLanguage := CreateSectionNode(nil, 'Languages');
  ndPlaylist := CreateSectionNode(nil, 'Playlist');
end;
Und dann funktioniert auch das endlich
Delphi-Quellcode:
procedure TFMain.Button1Click(Sender: TObject);
var
  NodeD: ^rSectionsData;
  Node: PVirtualNode;
begin
  DMMedia.ZQ1.First;
  while NOT DMMedia.ZQ1.Eof do
  begin
    Node := VSTSections.AddChild(ndGenre);
    NodeD := VSTSections.GetNodeData(Node);
    NodeD.BasicND := TBasicNodeData.Create(DMMedia.ZQ1Genre.AsString);
    DMMedia.ZQ1.Next;
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:25 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz