Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change a propery of all or some items in an array at once 1

Status
Not open for further replies.

DelphiAaron

Programmer
Jul 4, 2002
826
AU
i have an array of buttons
i wish to change many or all of the buttons visible property at once.

i can do a loop and change them 1 at a time but wish to do it all at once if possible.

thanx

Aaron Taylor
John Mutch Electronics
 
Any process, no matter how deeply buried in a component it may be will resort to a loop to change each button one at a time. If you already have a TList or TObjectList containing each button, then this is the very easiest way of changing all of their properties.

I suppose the same could be done by posting a message, but each button would need to be a custom component with extra code added to check for the message. Plus, I think once a message has been read, it is removed from the queue, so only one button would respond anyway. Not 100% sure on that though.
 
If your buttons are physically close together on a form they could be placed on a TPanel component.

Then all you have to do is change the Visible property of the panel and this will hide or make visible all the components on the panel.

No loop required!
Code:
  panel1.Visible := false;
  ...
  panel1.Visible := true;

Andrew
Hampshire, UK
 
You didn't say it was a toolbar in your original post :)

You could put the TPanel component on your toobar and then add a second toolbar on the TPanel component. Put your buttons on this second toolbar. Then by changing the Visible property of the TPanel component you will change the visibility of only those buttons on the second toolbar.

Again this will only work if the geography of your buttons is suitable.

Andrew
Hampshire, UK
 
no
i wanted to keep the question simple and to the point.

i just wanted to do this without the buttons disapering 1 by 1

for i := 1 to 20 do button.visible:=false;



Aaron Taylor
John Mutch Electronics
 
I was under the impression that they would all disappear at once, because there is no screen refresh occurring within in the loop. For them to disappear one by one, your code would need to be:
Code:
for i := 1 to 20 do
begin
  button[i].Visible := False;
  Application.ProcessMessages;
end;
 
(I was under the impression that they would all disappear at once)

why is that when the code

for i := 1 to 26 do Button.Visible := False;

is effecting 1 button at a time ??????

its probably the toolbar component that makes it redraw each time a button is removed.

maybe i should try 26 to 1 because you remove button1 and buttons 2 to 26 then move to the left and so on.

for i := 26 downto 1 do Button.Visible := False;

Aaron Taylor
John Mutch Electronics
 
If your buttons are not of type TButton, then yes, they could have extra code to automatically redraw once their Visible property changes. If you have the VCL source code, you could have a look and see if this is the case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top