delphirules
delphirules

Reputation: 7408

How to iterate into components inside a TTabSheet

I'm trying to iterate between all components inside a TTabsheet. Problem is, inside this tab there are only a memo and a edit, but my code iterate between components in all form. What am I'm missing ?

var i : integer;
begin
with PageControl1.ActivePage do 
 for i := 0 to componentcount-1 do
   begin
   // componentcount should be 2, but actually is 95
   components[i].doSomething;
   end;
end;

Upvotes: 0

Views: 673

Answers (2)

Tycho
Tycho

Reputation: 101

Perhaps 'with' might have something to do about it. You cant really tell what the return value for 'componentcount' will be (might even return number of components for the form itself?).

Upvotes: 0

No'am Newman
No'am Newman

Reputation: 6477

I had something like this, where a button click caused code to traverse over all the controls that were on a tabsheet that was on a page control, using the components array. Later on I changed it to the following, that uses the controls array of the given tabsheet.

procedure TShowDocsByRank.CleanBtnClick(Sender: TObject);
var
 i: integer;

begin
 for i:= 0 to tabsheet1.controlcount - 1 do
  if tabsheet1.controls[i] is TLabeledEdit
   then TLabeledEdit (tabsheet1.controls[i]).text:= ''
  else if tabsheet1.controls[i] is TComboBox
   then TComboBox (tabsheet1.controls[i]).text:= '-';
end;

Upvotes: 1

Related Questions