Page 1 of 1
How to access button objects in an array of buttons?
Posted: Fri Aug 07, 2009 1:14 pm
by ConvertFromOldNGs
by Eric Apperley >> Wed, 7 Nov 2007 23:16:49 GMT
Let's say I have 6 buttons and I need to do something to each, e.g. change the colour of each button. I would like to use a loop of course, but I don't know how to address each button...
In Delphi or VB.Net I'd iterate through the collection of controls of type button .
Its probably just as simple in JADE. Can someone give me a wee code snippet to show how to do this?
Thanks,
Eric
Re: How to access button objects in an array of buttons?
Posted: Fri Aug 07, 2009 1:14 pm
by ConvertFromOldNGs
by BeeJay >> Thu, 8 Nov 2007 0:30:53 GMT
Form::controlCount and Form::controls should allow you to achieve the desired result. Here's a simple example of one way you might achieve the desired result:
vars
controlIndex : Integer ;
ctl : Control ;
begin
foreach controlIndex in 1 to self.controlCount do
ctl := self.controls( controlIndex );
if ctl.isKindOf( Button ) then
// Do something to the button
endif;
endforeach;
end;
Re: How to access button objects in an array of buttons?
Posted: Fri Aug 07, 2009 1:14 pm
by ConvertFromOldNGs
by Allistar >> Thu, 8 Nov 2007 0:48:07 GMT
Hi could always add the buttons to a collection held on the form, and then iterate through them at some point.
Adding buttons to the collection:
- define a property (allButtons) of type ControlArray to the form (make it "exclusive").
- in the "load" event on the form add the buttons to the array:
allButtons.add(btOne);
allButtons.add(btTwo);
allButtons.add(btThree);
Then when you need to iterate through them, do this:
vars
button: Button;
iter: Iterator;begin
iter := allButtons.createIterator();
while (iter.next(button)) do
button.foreColor := Green;
endwhile;
epilog
delete iter;
end;
--
A.
Re: How to access button objects in an array of buttons?
Posted: Fri Aug 07, 2009 1:14 pm
by ConvertFromOldNGs
by cnwjhp1 >> Thu, 8 Nov 2007 1:17:54 GMT
.....and if you are dynamically creating the controls with addControl or loadControl, you could add them into your collections as you create them.