?
Solved

Treeview and Selected Item

Posted on 2006-04-06
3
Medium Priority
?
717 Views
Last Modified: 2010-04-05
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



0
Comment
Question by:Fled
3 Comments
 
LVL 2

Expert Comment

by:alijunior
ID: 16393338
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
0
 

Author Comment

by:Fled
ID: 16393525
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;
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 1000 total points
ID: 16398055
this would be the correct access:

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

meikl ;-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question