Board index » delphi » Please help e how can i get especific ancestor node of treeview

Please help e how can i get especific ancestor node of treeview

Please help e how can i get especific ancestor node
 ??///

see code:

procedure TfrmManager.trvObrasChange(Sender: TObject; Node: TTreeNode);
begin
  with frmMain do
  case Node.Level of
    0:   with ObjCorbar do
         begin
           Centrais:= Node.Text;
           Clientes:= EmptyStr;
           Obras:= EmptyStr;
           Plantas:= EmptyStr;
           Elementos:= EmptyStr;
         end;
    1:   with ObjCorbar do
         begin
           Centrais:= Node.Parent.Text;
           Clientes:= Node.Text;
           Obras:= EmptyStr;
           Plantas:= EmptyStr;
           Elementos:= EmptyStr;
         end;
    2:   with ObjCorbar do
         begin
           Centrais:= ??????????;          <------  ?????? How can i get this ancestor node
           Clientes:= Node.Parent.Text;
           Obras:= Node..Text;
           Plantas:= EmptyStr;
           Elementos:= EmptyStr;
         end;
    3:   with ObjCorbar do
         begin
           Centrais:= ???????????????;  <------  ?????? How can i get this ancestor node
           Clientes:= ???????????????;  <------  ?????? How can i get this ancestor node
           Obras:= Node.Parent.Text;
           Plantas:= Node..Text;
           Elementos:= EmptyStr;
         end;
  end;
  with frmMain do
  begin
  Label1.Caption:= ObjCorbar.Centrais;
  Label2.Caption:= ObjCorbar.Clientes;
  Label3.Caption:= ObjCorbar.Obras;
  Label4.Caption:= ObjCorbar.Plantas;
  end;

end;

 

Re:Please help e how can i get especific ancestor node of treeview


Quote
"westsoftwares" wrote...

> Please help me how can i get specific ancestor node

> see code:
> [snipped]

If you have a node you can use the parent as
you already do and from that node check the
parent and so on until you reach the node
which doesn't have a parent (=nil) at this moment
you are at the top level.

But the problem is that you want to 'reverse' the order of
the strings compared to the order in which they are found.

Maybe next code will help...

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
  I: Integer;
  NodeTexts: array[0..4] of string;
begin
  // First get all possible Text from the node
  // and its parent nodes.
  for I := Node.Level downto 0 do
  begin
    NodeTexts[I] := Node.Text;
    Node := Node.Parent;
  end;

  with ObjCorbar do
  begin
    Centrais  := NodeTexts[0];
    Clientes  := NodeTexts[1];
    Obras     := NodeTexts[2];
    Plantas   := NodeTexts[3];
    Elementos := NodeTexts[4];
  end;

  Label1.Caption := ObjCorbar.Centrais;
  Label2.Caption := ObjCorbar.Clientes;
  Label3.Caption := ObjCorbar.Obras;
  Label4.Caption := ObjCorbar.Plantas;
  Label5.Caption := ObjCorbar.Elementos;
end;

--
Pieter

Re:Please help e how can i get especific ancestor node of treeview


Quote
In article <3d15c2ce$1_2@dnews>, Westsoftwares wrote:

Duplicate post answered in b.p.d.ObjectPascal.

Please do not post your question to several of the newsgroups at once, it is against the
forum guidelines (see http://www.borland.com/newsgroups/) and just wastes resources (both
server and human, somebody might spend time on answering a post that has already been
answered in another newsgroup).

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Other Threads