How can a button remove itself from a card?

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
Havanna
Posts: 53
Joined: Wed May 14, 2014 3:00 pm

How can a button remove itself from a card?

Post by Havanna » Fri Nov 21, 2014 3:27 pm

I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.

The remove button takes the item out of an items array, removes the corresponding field from the card.
Finally of course it should dispose of itself.
This naturally fails with an (Object: stack locked, of object's script is executing) - as the button holds the self destruction order.

Is there a way to acomplish self-destruction other than going to another card and put the cleanup of the list into the preopencard when it is opened the next time?

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: How can a button remove itself from a card?

Post by magice » Fri Nov 21, 2014 3:29 pm

Put a handler in the stack to remove the button then use "send" to call that handler.

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: How can a button remove itself from a card?

Post by newtronsols » Fri Nov 21, 2014 5:11 pm

Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
?
Do you have a clever way to dynamically position objects for any device - tablet etc?

I'm still waiting to figure out how to get fullscreenmode "exactfit" etc to work with a scrolling group of objects any phone/tablet size landscape/portrait.

I did experiment using screenrect and then changing the width, height factor of this rect to calc the scroller contentrect for either landscape or portrait.
or set the scaleFactor of stack "Stack" to ... but I didn't resolve it.
Last edited by newtronsols on Fri Nov 21, 2014 5:12 pm, edited 1 time in total.

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: How can a button remove itself from a card?

Post by newtronsols » Fri Nov 21, 2014 5:11 pm

Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
?
Do you have a clever way to dynamically position objects for any device - tablet etc?

I'm still waiting to figure out how to get fullscreenmode "exactfit" etc to work with a scrolling group of objects any phone/tablet size landscape/portrait.

I did experiment using screenrect and then changing the width, height factor of this rect to calc the scroller contentrect for either landscape or portrait.
or set the scaleFactor of stack "Stack" to ... but I didn't resolve it.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How can a button remove itself from a card?

Post by FourthWorld » Fri Nov 21, 2014 5:20 pm

Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.

The remove button takes the item out of an items array, removes the corresponding field from the card.
Finally of course it should dispose of itself.
If the button will ever be needed again in the future beyond that one use, why not just hide it?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Havanna
Posts: 53
Joined: Wed May 14, 2014 3:00 pm

Re: How can a button remove itself from a card?

Post by Havanna » Sat Nov 22, 2014 7:49 pm

FourthWorld wrote:
Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.

The remove button takes the item out of an items array, removes the corresponding field from the card.
Finally of course it should dispose of itself.
If the button will ever be needed again in the future beyond that one use, why not just hide it?
This List is a set of "Favourites" without Limitation, so a user can have between no and an "unlimited" number of Entries.
I had a first version with the hide and show approach, but handling of this just looks easier to me when I create and remove the items instead of keeping control over a set of un/-visible objects.

Havanna
Posts: 53
Joined: Wed May 14, 2014 3:00 pm

Re: How can a button remove itself from a card?

Post by Havanna » Sat Nov 22, 2014 8:05 pm

newtronsols wrote:
Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
?
Do you have a clever way to dynamically position objects for any device - tablet etc?
I don't know if that's clever but it mostly works:
I use a handler to determine all relevant layout values and put them into a global array, so I can acces that from anywhere.
This handler is called on startup (and resize)
I set FontSizes and Layout margins and button sizes from here
Position of Objects i find reasonably simple by making "Object type Handlers" like: SetButton ButtonID, tButtonType, tButtonColor, tTextColor
in there I calculate the details from global button size, global button spacing and so on. Also a global "Left" and "Top" value make for a sort of Layout cursor, that gets updated in every "Object Type Handler"

Works quite nicely, but is a lot of codewriting of course, with the benefit of full layout control.
For different platforms and orientations, differend layout basics handlers do the job for me.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: How can a button remove itself from a card?

Post by richmond62 » Sat Nov 22, 2014 10:43 pm

on mouseUp
delete button "XX"
end mouseUp

dead easy

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: How can a button remove itself from a card?

Post by richmond62 » Sat Nov 22, 2014 10:53 pm

mind you a button CANNOT delete itself

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: How can a button remove itself from a card?

Post by bn » Sat Nov 22, 2014 11:19 pm

Hi Havanna,

make a button

Code: Select all

on mouseUp
   put the long id of me into tLID
   send "delete tLID" to this card in 5 milliseconds
end mouseUp
the button is gone.

Of course you put similar code into your self-destruction handler.

Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: How can a button remove itself from a card?

Post by bn » Sat Nov 22, 2014 11:29 pm

You can also put

Code: Select all

on mouseUp
   put the long id of me into tLID
   send "delete tLID" to me in 5 milliseconds
end mouseUp
into the script of the button. The button is gone after mouseUp

The main reason an object can not delete itself is that the code to delete is still running. With "send in time" the code is not running anymore and deletion can happen.

Kind regards
Bernd

Havanna
Posts: 53
Joined: Wed May 14, 2014 3:00 pm

Re: How can a button remove itself from a card?

Post by Havanna » Sun Nov 23, 2014 1:42 pm

bn wrote: The main reason an object can not delete itself is that the code to delete is still running. With "send in time" the code is not running anymore and deletion can happen.
Bernd, that is a very interesting situation, I wouldn't have expected time to make a difference. Instead I thought deleting an object would only be possible from the outside thanks a lot.

Andreas

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How can a button remove itself from a card?

Post by FourthWorld » Fri Nov 28, 2014 3:20 pm

Havanna wrote:I wouldn't have expected time to make a difference. Instead I thought deleting an object would only be possible from the outside thanks a lot.
Your expectation is spot-on: the "delete" command is being handled by the engine, and with the delay in sending it occurs after the button's own script has completed. So at that point, the actual deletion is being handled outside the button script.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply