Iterate through components on TTabSheet lazarus / 31-LCL ---------------------------------------------------------------------- ProgEd · 2013-03-13 14:28 I have a TTabSheet with lots of TEdit fields on it. I'm looking for a way to write a single event handler for all of them (they get processed identically). I'd also like to be able to iterate through all of them when I'm ready to save the data that's been entered. My memory tells me there's an enumerator that does this, but I can't remember what it is or how to use it. Can anyone help me, please? Ed ---------------------------------------------------------------------- Blaazen · 2013-03-13 14:53 If you want single handler you need: Code: [Select]with (Sender as TEdit) do ...it will always take actual TEdit. To list all Edits on TabSheet is a little more difficult because owner is always TForm but Parent is TabSheet. Try this: Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin   for i:=0 to ComponentCount-1 do     if (Components[i] is TEdit) then       if (Components[i] as TEdit).Parent=TabSheet1 then writeln(Components[i].Name); end; ---------------------------------------------------------------------- ProgEd · 2013-03-13 15:50 Thank you! Precisely what I was looking for. Ed ---------------------------------------------------------------------- taazz · 2013-03-13 16:49 Actually its even easier instead of components use controls. eg Code: [Select]var   vCnt : Integer; begin   for vCnt := 0 to TabSheet2.ControlCount -1 do   begin     TabSheet2.Controls[vCnt].Enabled := not TabSheet2.Controls[vCnt].Enabled;   end; end; Components has all the objects that the component owns controls collection has all the objects that it parents. ---------------------------------------------------------------------- Blaazen · 2013-03-13 16:55 Yes, this way is better. Code: [Select]var i: Integer; begin   for i:=0 to TabSheet1.ControlCount-1 do     if TabSheet1.Controls[i] is TEdit then ... ; ---------------------------------------------------------------------- vrull · 2013-03-18 20:09 Not sure, if it's true for Lazarus, but in Delphi the control is not in the list if it's placed on the child container, like TPanel ot TTabSheet. So iterating through Components on the form will give you everything on the form, but Controls suit better if you are interested in a particular TabSheet which has no child containers. ---------------------------------------------------------------------- User137 · 2013-03-19 00:02 There is also panel1.Controls[]... Reason that using Controls-array is better, is that the array to go through is more propably precise and smaller, faster. If you have a complicated form with many controls, then going through Components would result in lots of false matches.