Author: Tomas Rutkauskas
How to color TPanels on a form according to their Tag properties
Answer:
1 { ... }2 var3 ix: Integer;
4 pnl: TPanel;
5 { ... }6 7 for ix := 0 to ComponentCount - 1 do8 begin9 if Components[ix] is TPanel then10 begin11 pnl := TPanel(Components[ix]);
12 case pnl.Tag of13 1: pnl.Color := clRed;
14 2: pnl.Color := clBlue;
15 else16 pnl.Color := clBtnFace;
17 end;
18 end;
19 end;
Try placing the above code in a button OnClick event handler (having dropped some TPanels on the form with different Tag values).