Page 1 of 1

deletecard

Posted: Thu Jun 12, 2014 5:06 am
by robm80
Fld pagnum is the linenumber of the selectectedtext of field "index" of group "BGrIndex".
I want to delete card "foo", pagnum=82

You see there is something wrong in deleting this card; I tried 'deletecard': nope!
What's the right syntax?
sshot-1.jpg

Re: deletecard

Posted: Thu Jun 12, 2014 5:31 am
by dunbarx
Hi.

"DeleteCard" is a message, not a command. It is sent, like "mouseUp", when the appropriate event is detected by the engine.

"Delete", on the other hand, IS a command, and is what you need. Please see the dictionary for this. It is quite flexible, as you will see. For example, you can delete any card in any stack anywhere as long as the reference to that card is valid.

Craig Newman

Re: deletecard

Posted: Thu Jun 12, 2014 8:40 am
by robm80
I have taken notice of the dictionnary and that's the reason of my question.
Have a look of both examples that do not work (fld index is a field with backgroundbehaviour):

on mouseUp
put fld pagnum into tLO
delete card (line tLO of fld index of group "BGrIndex")
put empty into line tLO of fld "index"
filter fld "index" without empty
end mouseUp

and

on mouseUp
##put selectedtext of fld "index" of group "BGrIndex" --is OK
put fld pagnum into tLO
delete card (selectedtext of fld "index" of group "BGrIndex")
put empty into line tLO of fld "index" of group "BGrIndex"
filter fld "index" of group "BGrIndex" without empty
end mouseUp

Thanks

Re: delete card

Posted: Thu Jun 12, 2014 10:53 am
by robm80
This one works NOT:
sshot-5.jpg
sshot-5.jpg (18.1 KiB) Viewed 7014 times

This one (message box) no problem. What's the difference :?:
sshot-3.jpg
sshot-3.jpg (20.61 KiB) Viewed 7014 times

Re: deletecard

Posted: Thu Jun 12, 2014 11:44 am
by Klaus
Hi Rob,

do you get an error dialog? If yes, what does it tell?

ONE possible problem is, that you cannot delete a card on which a script is currently excecuting!
is this the case here? I mean are you doing this on the card you want to delete?

Add an ANSWER dialog, which is ALWAYS a good way to show possible errors:
...
delete card XYZ
ANSWER THE RESULT
## THis should be EMPTY on success and give a hint on what is going wrong.
...

Hint:
Instead of putting EMPTY into a line, simply delete it, so no need to FILTER afterwards:
...
delete line tLO of fld "index"
## DONE!

## Not neccessary anymore:
## filter line ...
...

Best

Klaus

Re: deletecard

Posted: Thu Jun 12, 2014 1:57 pm
by robm80
do you get an error dialog? If yes, what does it tell? NO

ONE possible problem is, that you cannot delete a card on which a script is currently excecuting!
is this the case here? I mean are you doing this on the card you want to delete? YES :!: See next question

Add an ANSWER dialog, which is ALWAYS a good way to show possible errors:
...
delete card XYZ
ANSWER THE RESULT
## THis should be EMPTY on success and give a hint on what is going wrong. OK
...

Hint:
Instead of putting EMPTY into a line, simply delete it, so no need to FILTER afterwards: OK
...
delete line tLO of fld "index"
## DONE! YES

## Not neccessary anymore:
## filter line ...
OK

Next question:
I want to delete the last card, so I have to tell the del-button the name of that card.
I think that can only be done with the message box.
But when using the message box, it is no problem to copy the goodrunning script to the message box.
sshot-9.jpg
sshot-9.jpg (19.68 KiB) Viewed 6992 times
Or do you see a better way?
Rob

Re: deletecard

Posted: Thu Jun 12, 2014 3:57 pm
by Klaus
Hi Rob,
I want to delete the last card, so I have to tell the del-button the name of that card.
1. What about "last cd"?

2. Do you mean the LAST card (and only one left)?
Or the last card (of X cards)?

3. As I wrote, you cannot delete the card where the current script is running!

BEWARE: When you delete the LAST (and only one) card of a stack, the card will be deleted WITH ALL CONTROLS ON IT!!!,
but since a stack MUST always have at least ONE card, a new and EMPTY card will be created immediately.

Is that what you want?

4. Because of 3. you should "outsource" the "dleteing" to another handler in the stack script like this:

Code: Select all

command delete_card
  put the selectedtext of fld "index into ttSLT
  ## More field stuff here...
  ### ...
  delete cd tSLT
end delete_card
then call it on mouseup with a little delay, so the mouseup script is finished before the card will be deleted:

Code: Select all

on mouseup
  send "delete_card" to this stack in 1
end mouseup
Best

Klaus

Re: deletecard

Posted: Fri Jun 13, 2014 6:11 am
by robm80
Thanks Klaus,
My explanation was bad. In fact I have a stack with 300 cards and from time to time I have to delete one. That's all.
The fuzz about the last card was because it was the last card I wanted to delete, succecfully with the message box.
Now I wil use your suggestion with the command.
Rob

Re: deletecard

Posted: Fri Jun 13, 2014 6:54 am
by robm80
Sorry Klaus, I need more help...
I made 2 commands in the stackscript, one for delete and one for create card:

command delete_card
put selectedtext of fld "index" into tSLT
put lineoffset(tSLT,field "index") into tLO
put tLO into fld pagnum
delete card tSLT
del line tLO of fld "index"
end delete_card


command create-card --in the createbutton tName got a content
global tName
create card tName
put tName into fld "pagnam"
put cr & tName after fld "index"
sort lines of fld "index"
end create_card

and I made 2 buttons, in which I uncritically copied your suggestion:

DELETEBUTTON
on mouseup
send "delete_card" to this stack in 1
end mouseup

CREATEBUTTON
on mouseup
global tName
put "Willem" into tName
send "create_card" to this stack in 1
end mouseup

The whole effort did not work.??
Waht means "in 1": time??

Re: deletecard

Posted: Fri Jun 13, 2014 7:54 am
by Simon
Hi Rob,
Waht means "in 1": time??
The send command has a time component, "send "delete_card" to this stack in 1" will send the message in 1 "tick" (1/60 of a second). Because the messagebox is working, as you have said, Klaus's idea is that all scripts must stop running on the card being deleted. send in 1 will allow the mouseUp to finish before the message is sent i.e. all scripts have stopped running.

Well I've been trying it here and I can't stop the card from being deleted even with the on closeCard running a script.
Something else is amiss.

Simon
Edit:
With this code:

Code: Select all

put selectedtext of fld "index" into tSLT 
put lineoffset(tSLT, field "index") into tL0 
breakpoint
put tL0 into fld pagnum 
delete card tSLT 
delete line tL0 of fld "index"
 
What exactly does tSLT hold at the breakpoint? Check for spaces.
(Hey gang I used "Introducing the new LiveCode stack file formats…JPEG & PNG?" http://livecode.com/blog/2014/05/30/int ... -jpeg-png/ the first time for this) :)

Re: deletecard

Posted: Sat Jun 14, 2014 9:25 am
by robm80
No breakpoint here, but when the stackcript is:

command delete_card
put selectedtext of fld "index" into tSLT
put lineoffset(tSLT,field "index") into tLO
put tLO into fld pagnum
delete card tSLT
delete line tLO of fld "index"
end delete_card


delete_card funcions OK, when called with
on mouseup
send "delete_card" to this stack in 1
end mouseup


but when I add another command to the stackscript:
command delete_card
put selectedtext of fld "index" into tSLT
put lineoffset(tSLT,field "index") into tLO
put tLO into fld pagnum
delete card tSLT
delete line tLO of fld "index"
end delete_card

command create-card
global tName
put tName into tVar
create card tVar
put tVar into fld "pagnam"
put cr & tVar after fld "index"
sort lines of fld "index"
end create_card


none of both commands funtions. How many commands in the stackscript :?:

When i put the create_card in the stackscript alone, it does not function either, when called with:
on mouseup
global tName
put "Willem" into tName
send "create_card" to this stack in 1
end mouseup


What am I doing wrong this time?
And probably the create-card is a stupid script :!:

Re: deletecard

Posted: Sat Jun 14, 2014 1:00 pm
by Simon
Hi Rob,
I get an error on this:
command create-card
It's in your post, not surprising it doesn't work.

Tip, see that button above "Code"?
Just select your code and hit that, better than images and red text. And the button "Preview" below will allow you to see it before it's posted.

Good to hear you've solved the delete card problem.

Simon

Re: deletecard

Posted: Sat Jun 14, 2014 4:59 pm
by robm80
You find my postings "overdone" :OK.
Meanwhile you attended me on a typo and now all runs smoothly.
Rob