### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: How to solve problem about many panels  (Read 8840 times)

• New Member
• Posts: 20
##### How to solve problem about many panels
« on: July 21, 2011, 08:58:37 pm »
I have 55 panels on my form.
Every panel change color, and many others things
Example :

In Delphi I solve proble like this

for i:=201 to 255
begin
Case nPanel of
201: Panel201.Color:=clBlue;
.
.
.
255: Panel255.Color:=clWhite;
end;
end;

In clipper I wihil something like this :

for i=1 to 55
&("Panel"+STR(i)).Color:=PripadajućaBoja (I know that Clipper dont have command like this, this is onely exaple)
next i

Can Delphi do this like Clipper?
Može li Delphi da odradi nešto ovako kao Clipper?

#### typo

• Hero Member
• Posts: 3051
##### Re: How to solve problem about many panels
« Reply #1 on: July 21, 2011, 09:18:44 pm »
Code: [Select]
`for i:=201 to 255 do    TPanel(FindComponent('Panel' + IntToStr(i))).Color := clBlue; `

• New Member
• Posts: 20
##### Re: How to solve problem about many panels
« Reply #2 on: July 22, 2011, 09:52:42 am »
Thamk You !!!!

• New Member
• Posts: 20
##### Re: How to solve problem about many panels
« Reply #3 on: July 22, 2011, 09:54:46 am »
Thank You typo !!!

#### m.vincent

• New Member
• Posts: 17
##### Re: How to solve problem about many panels
« Reply #4 on: September 26, 2011, 03:36:01 pm »

for i:=201 to 255 do
if ( FindComponent('Panel' + IntToStr(i)) is TPanel) then
(FindComponent('Panel' + IntToStr(i)) as TPanel).Color := clBlue;

This way you can iterate through the list of componets on a form and take different action for different component types.

Regards,

Mike

#### Arbee

• Full Member
• Posts: 223
##### Re: How to solve problem about many panels
« Reply #5 on: September 26, 2011, 04:20:55 pm »
Although you're absolutely right Mike, I don't think a lot of people would call their comboboxes "panelxxx".
1.0/2.6.0  XP SP3 & OS X 10.6.8

#### User137

• Hero Member
• Posts: 1791
##### Re: How to solve problem about many panels
« Reply #6 on: September 26, 2011, 06:26:37 pm »
I wouldn't make any panel in the design view, but create them manually.
Code: [Select]
`private  myPanel: array[0..255] of TPanel;for i:=0 to 255 do begin  myPanel[i]:=TPanel.Create(form1);  ... set its propertiesend;`
... because FindComponent() is much slower and you don't have to manually draw them in the design, but have the exact properties mathematically right.
« Last Edit: September 26, 2011, 06:28:10 pm by User137 »

#### m.vincent

• New Member
• Posts: 17
##### Re: How to solve problem about many panels
« Reply #7 on: September 26, 2011, 06:39:30 pm »
Although you're absolutely right Mike, I don't think a lot of people would call their comboboxes "panelxxx".

LOL - indeed.

Mike