Treeview and Selected Item

Hello,

How can i access the selected Object index or ChildObject index in a treeview?  It seems differents then the ListBox

  Desactiver1.Enabled := (TAppareils(Treeview1.Selected).Active = 'true');  

This work (Treeview1.Selected), but not when i access one of is childs... i receive an acess violation.

Thanks



FledAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alijuniorCommented:
Hi Fled...

What is "TAppareils" ???

The code

  Caption := TreeView1.Selected.Text;

works fine! May be the cast of class TTreeNode to TAppareils raise the error...

The class of childs and "parents" are the same (TTreeNode) in the TreeView.Items... The difference are that the root members has Parent = nil, and childs not.

Post the complete code to help me help you...

[]'s
FledAuthor Commented:
TAppareils is a user class..  This is the code to fill the treeview...

var
  UnAppareil : TAppareils;
  Node : TTreeNode;
  ChildNode : TTreeNode;
  PlageHaut, PlageBas : string;
begin

    if not CDSAppareils.Active then
        CDSAppareils.Active := true;

    CDSAppareils.First;

    While not CDSAppareils.Eof do
    begin
      UnAppareil := TAppareils.Create;
      Node := TTreeNode.Create(nil);

      UnAppareil.NomLogique     := CDSAppareils.FieldValues['chr_NomLogique'];
      UnAppareil.Manufacturier  := CDSAppareils.FieldValues['chr_Manufacturier'];
      UnAppareil.Identificateur := CDSAppareils.FieldValues['chr_Identificateur'];
      UnAppareil.NoSerie        := CDSAppareils.FieldValues['chr_NoSerie'];
      UnAppareil.NoModele       := CDSAppareils.FieldValues['Chr_NoModele'];
      UnAppareil.Active         := CDSAppareils.FieldValues['chr_Actif'];
      UnAppareil.PlageUtilBas   := CDSAppareils.FieldValues['flo_PlageBas'];
      UnAppareil.PlageUtilHaut  := CDSAppareils.FieldValues['flo_PlageHaut'];
      UnAppareil.Resolution     := CDSAppareils.FieldValues['chr_Resolution'];
      UnAppareil.Exactitude     := CDSAppareils.FieldValues['chr_Exactitude'];

      PlageHaut                 := format('%.1f °C', [UnAppareil.PlageUtilHaut]);
      PlageBas                  := format('%.1f °C', [UnAppareil.PlageUtilBas]);

      Form1.TreeView1.Images    := form1.ImageList1;

      Node := Form1.TreeView1.Items.AddObject(nil, UnAppareil.NomLogique, UnAppareil);

      ChildNode := Form1.Treeview1.Items.AddChildObject(Node, UnAppareil.Identificateur + ' - ' +
                    Trim(UnAppareil.Manufacturier) + ' - ' + 'Serie: ' + UnAppareil.NoSerie
                    + ' - ' + 'Model: ' + UnAppareil.NoModele + ' - ' + 'Exact: ' +
                    UnAppareil.Exactitude + ' - ' + 'Resol: ' + UnAppareil.Resolution + ' - '
                    + 'Plages: ( ' + PlageBas + ' - ' + PlageHaut + ' ) ', UnAppareil);


      if UnAppareil.Active = 'true' then
        begin
          node.ImageIndex     := 2;
          node.SelectedIndex  := 2;
          ChildNode.ImageIndex := 2;
          ChildNode.SelectedIndex := 2;

        end
      else
        begin
          node.ImageIndex     := 3;
          node.SelectedIndex  := 3;
          ChildNode.ImageIndex := 3;
          ChildNode.SelectedIndex := 3;

        end;

       CDSAppareils.next;
    end;

    CDSAppareils.Close;

end;
kretzschmarCommented:
this would be the correct access:

Desactiver1.Enabled := (TAppareils(Treeview1.Selected.Data).Active = 'true');  

meikl ;-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.