Lazarus
Miscellaneous => Suggestions => IDE/CodeTools => Topic started 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?
-
for i:=201 to 255 do
TPanel(FindComponent('Panel' + IntToStr(i))).Color := clBlue;
-
Thamk You !!!!
-
Thank You typo !!!
-
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
-
Although you're absolutely right Mike, I don't think a lot of people would call their comboboxes "panelxxx". :)
-
I wouldn't make any panel in the design view, but create them manually.
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.
-
Although you're absolutely right Mike, I don't think a lot of people would call their comboboxes "panelxxx". :)
LOL - indeed.
Mike