Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: For i=0 to


This question is answered.


Permlink Replies: 2 - Last Post: Apr 1, 2018 6:14 AM Last Post By: Melissa Torn Threads: [ Previous | Next ]
Melissa Torn

Posts: 143
Registered: 4/30/09
For i=0 to  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 1, 2018 5:33 AM
I have a Panel and a Page Control on the Panel
and there are 5, 6 treeviews on the different tabsheets
I want to Expand the ALL treeviews on the form create event
I wrote below code but doesnt work (no error)

for i:=0 to Panel1.ComponentCount-1 do
begin
if Panel1.Components[i] is TTreeView then
(Panel1.Components[i] as TTreeView).FullExpand;
end;

Thank You
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: For i=0 to
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 1, 2018 5:52 AM   in response to: Melissa Torn in response to: Melissa Torn
Melissa Torn wrote:

I have a Panel and a Page Control on the Panel
and there are 5, 6 treeviews on the different tabsheets
I want to Expand the ALL treeviews on the form create event
I wrote below code but doesnt work (no error)

for i:=0 to Panel1.ComponentCount-1 do

The code assumes that the treeviews are owned by panel1. This will not
be the case if you constructed the form in the designer, by dropping
the treeviews on the pagecontrol pages. In this case the treeviews are
owned by the form, so you have to use the form's Components array, not
the one of panel1. This will then of course also find treeviews that
are not contained on one of the pagecontrol pages. If your form does
not have any not on pagecontrol pages you could use

for i:= 0 to ComponentCount-1 do
if Components[i] is TTreeview then
TTreeview(Components[i].FullExpand;

The other option is to enumerate the pagecontrol pages with a for loop
and then look for the treeviews in the pages' Controls array. THat only
works if the treeviews are directly dropped on a page, not on a panel
on the pages or such. The Controls array of a TWinControl contains the
controls that that TWinControl as Parent.

If the form design is complex but the treeviews are still owned by the
form you could also kind of invert the search. You start with a loop
over the form's COmponents array. For each treeview you find you then
walk up the treeview's Parent chain, and if you find a TTabsheet you
expand the treeview, if you end up on the form level (or panel1) you do
nothing with this treeview.

--
Peter Below
TeamB

Melissa Torn

Posts: 143
Registered: 4/30/09
Re: For i=0 to  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 1, 2018 6:14 AM   in response to: Peter Below in response to: Peter Below
Thank you so much Peter
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02