Delete more than one button

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
sinep
Posts: 12
Joined: Sat Jun 13, 2015 5:19 am

Delete more than one button

Post by sinep » Thu Jun 25, 2015 2:03 am

I made a button with the intention that it will reset the page or delete all of the buttons that were created by the user.

the following works for deleting one button:

on mouseUp
delete button "mybutton1"
end mouseUp

the following also seems to work:

on mouseUp
delete button "mybutton1" and button "mybutton2"
end mouseUp

However, if I have more than one "mybutton1" on the page it will only delete the last one created and not all of them and if one of the buttons listed in that code an error occurs because it doesn't exist.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Delete more than one button

Post by dunbarx » Thu Jun 25, 2015 5:59 am

Hi.

Fun stuff. But you must be patient. Learning LiveCode requires effort, commitment and time. The good news it is easy and enjoyable to become fairly proficient, usually in only a couple of months.

I am always learning. I had no idea that:

Code: Select all

delete button "mybutton1" and button "mybutton2"
was even possible.I would have bet it would throw a runtime error. I am going to update the "delete" entry in the dictionary.

Anyone else surprised as I was???

Anyway. There are several ways to refer to controls. You already know about names. There are others, and these may be more suited to your task. But even names can be used, if you form your buttons in a way that lends itself to such a method. Say you did this:

Code: Select all

on mouseUp
repeat with y + 1 to the number of buttons
  if the name of button y contains "myBotton" then delete button y
end repeat
end mouseUp
Now you have to be careful if the button with this handler in it is also named "myButtonWhatever". Check out that old "delete" entry in the dictionary to see why. Makes sense, though, eh?

The seeds of some other methods are in the above handler. Foe example, what if you simply just deleted button y? Then the name would not matter at all. But, again, watch out for that little wrinkle I mentioned. Can you think of other ways?

Write back. There is much to get to know...

Craig Newman

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Delete more than one button

Post by SparkOut » Thu Jun 25, 2015 7:48 am

Surprised? Yes!
This is as odd as the "repeat with 1 = 1 to 9" thing.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Delete more than one button

Post by SparkOut » Thu Jun 25, 2015 7:51 am

And pssst, Craig... I will just mention "down to"

Post Reply