Lazarus

Miscellaneous => Suggestions => IDE/CodeTools => Topic started by: ribarvlada on July 21, 2011, 08:58:37 pm

Title: How to solve problem about many panels
Post by: ribarvlada 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;
    202: Panel202.Color:=clRead;
    .
    .
    .
    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?
Title: Re: How to solve problem about many panels
Post by: typo on July 21, 2011, 09:18:44 pm
Code: [Select]
for i:=201 to 255 do
    TPanel(FindComponent('Panel' + IntToStr(i))).Color := clBlue;
Title: Re: How to solve problem about many panels
Post by: ribarvlada on July 22, 2011, 09:52:42 am
Thamk You !!!!
Title: Re: How to solve problem about many panels
Post by: ribarvlada on July 22, 2011, 09:54:46 am
Thank You typo !!!
Title: Re: How to solve problem about many panels
Post by: m.vincent on September 26, 2011, 03:36:01 pm
Extending Typos answer and adding better/safer type-casting you could use:

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
 
Title: Re: How to solve problem about many panels
Post by: Arbee 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".  :)
Title: Re: How to solve problem about many panels
Post by: User137 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 properties
end;

... because FindComponent() is much slower and you don't have to manually draw them in the design, but have the exact properties mathematically right.
Title: Re: How to solve problem about many panels
Post by: m.vincent 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