Clear the data of a card when leaving the stack

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

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Clear the data of a card when leaving the stack

Post by Klaus » Fri Nov 23, 2018 7:49 pm

Hi Carles,

sorry, my spanish is almost not existent except some common phrases.
You can use "send script ..." but not in your case!

This is correct:
send script "answer the short name of me" to btn xyz
But in your case this is neccessary:
send "clearAllPisos" to card "Pisos"
See the difference?
the first one send a complete script and the second one only the name of a handler.

And you used: send script "clearAllPisos" OF card "Pisos"
The OF is completey wrong and may have thrown the error.
You send something TO a LC object. As I wrote you had it right in your first posting.

Code: Select all

If what LiveCode offers is not right, turn it off and let's go
Well, that was only a PROPOSAL of the autocomplete feature, which does not know what your really want to script in the end!

Best

Klaus

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Clear the data of a card when leaving the stack

Post by bogs » Fri Nov 23, 2018 8:50 pm

cbarbal wrote:
Fri Nov 23, 2018 7:39 pm
Regarding send script "clearAllPisos" of card "Pisos" in the second image you see: "send script message to object"

For me is not wrong syntax, send script message ("clearAllPisos") to object (of card "Pisos")

English:
For the record, I do not want to argue with someone who knows a lot more about LiveCode than me and who is helping me. For what I thank you and all those who have helped me in this forum.

When the "send" did not work I searched for an alternative that was "send script". If what LiveCode offers is not right, turn it off and let's go
Just some input that may (or may not) help a *little*.

The autocomplete statements your looking at (pictures 1 & 2) give you a general indication of the code that follows. lets see if we can break it down a bit more understandably.

C go card
"C" = command
"go" is the command
"card" is where your going, but you have to supply the card identifier, such as card 1, card "name", card id 1008, etc.

As far as I am aware, though, you can't just put "go card "myCard" (at least in the versions I use), you have to include "to", so it reads

Code: Select all

go to card "myCard"
I could be wrong, though, this is the second time I've come across the statement written that way, hopefully someone else has more input to add to this.

Now for the 'object' misunderstanding.
cbarbal wrote:
Fri Nov 23, 2018 7:39 pm
For me is not wrong syntax, send script message ("clearAllPisos") to object (of card "Pisos")
I can see why it is confusing to look at, but think of it like this. If you had a button, field, graphic, etc., you might write code like (bold marks for clarity)
send script "clearAll" to button "myButton" of card "myCard"
Of course, in this case we are trying to send the code to the card itself, so it would read
send script "clearAll" to card "myCard"
The only time you would include "of" in this instance is if you were clarifying which stack card "myCard" was part of, like this
send script "clearAll" to card "myCard" of stack "myStack
I hope that helps some.

*Edit - apparently Klaus beat me to the answer, and was more concise as well :D
Image

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Clear the data of a card when leaving the stack

Post by Klaus » Fri Nov 23, 2018 9:08 pm

Code: Select all

go cd "whatever"
without TO is in fact valid syntax.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Clear the data of a card when leaving the stack

Post by bogs » Fri Nov 23, 2018 9:44 pm

Good to know, in a recent posting about an article writing apps for Livecode, it errored here, so I just assumed it was due to the missing 'to' part.

Of course, now that I think about it more, it might have been a missing 'go' instead :oops:
Image

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Clear the data of a card when leaving the stack

Post by cbarbal » Sat Nov 24, 2018 11:40 am

I do not know what else to do. I put the "to" and I get an error (can't find background) in set the dgData of group "dgFinques" to empty

Code: Select all

on clearDatagridFinques
   set the dgData of group "dgFinques" to empty
   set the dgProp["sort by column"] of group "dgFinques" to empty
end clearDatagridFinques
I close the debugger and it disappears from the screen, if I look with the Project Browser I still have it in memory.

If someone wants to take a look, tell me in private and send it to them. The data is fake and the structure of the table comes from FileMaker and is partially modified. It is in Catalan but all the scripts are in English, with four instructions we pass. Just that you click on the "Conexio" button and then on the "Sortir" button you will have the error, it's that easy. Anyway, if I send it, I'll put the buttons that are used in English.

Regards,

Carles

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Clear the data of a card when leaving the stack

Post by Klaus » Sat Nov 24, 2018 11:49 am

Hola Carles,

I will take a look, just send your stack to -> klaus AT major-k.de


Best

Klaus

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Clear the data of a card when leaving the stack

Post by cbarbal » Sat Nov 24, 2018 12:22 pm

Hi Klaus,

I make a small manual in English, I change the buttons and I send it compressed, they are about 700kb. I'll look to send it before 2:00 pm.

Danke,

Carles

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Clear the data of a card when leaving the stack

Post by Klaus » Sat Nov 24, 2018 3:53 pm

Hi all,

no idea whyt this always throws an error in th cardscript -> no such object
Although the object is in fact on taht card:

Code: Select all

on clearAllCards
   lock screen
   ## There was an preopencard script on one card, 
   ## which should not be executed here, so I added:
   lock messages
   go card "Finques"
   send "clearAllFinques" to card "Finques"
   go card "Pisos"
   send "clearAllPisos" to card "Pisos"
end clearAllCards
In my tests this did work as exspected, however there were no datagrids involved in my tests as in Carles stack.

After some guessing and testing I found that this does works without any errors:

Code: Select all

on clearAllCards
   lock screen
   lock messages
   go card "Finques"
   call "clearAllFinques" of card "Finques"
   go card "Pisos"
   call "clearAllPisos" of card "Pisos"
end clearAllCards
No idea why, but years ago I stopped asking myself "Why, oh why?" when I found a workaround and my life is very easy since then! :-D


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7227
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Clear the data of a card when leaving the stack

Post by jacque » Sun Nov 25, 2018 7:07 pm

I'm not sure what's going on either. If you're on the card you shouldn't need either "send" or "call", you should be able to use the command directly. Odd. And what's the object that isn't found? A card isn't an object so it must be something the clearAllFinques handler is looking for. Stepping into that handler might reveal the mystery object.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Clear the data of a card when leaving the stack

Post by cbarbal » Mon Nov 26, 2018 7:21 pm

Hi jacque,

The clearAllFinques handler and subhandlers

Code: Select all

on clearAllFinques
   clearDatagridFinques
   clearDatagridPisos
   clearDatagridTotals
   clearRecordFinques
   clearGroupTotals
end clearAllFinques

on clearDatagridFinques
   set the dgData of group "dgFinques" to empty
   set the dgProp["sort by column"] of group "dgFinques" to empty
end clearDatagridFinques

on clearDatagridPisos
   set the dgData of group "Pisos" to empty
   set the dgProp["sort by column"] of group "Pisos" to empty
end clearDatagridPisos

on clearDatagridTotals
   set the dgData of group "Totals" to empty
   set the dgProp["sort by column"] of group "Totals" to empty
end clearDatagridTotals

on clearRecordFinques
   repeat with i = 1 to the number of fields of group "grpFields"
      put empty into the field i of group "grpFields"
   end repeat
   set text of field "lblSelect" to empty
end clearRecordFinques

on clearGroupTotals
   set the text of field "SumIngres" to empty
   set the text of field "SumDespesa" to empty
   set the text of field "SumSaldo" to empty
end clearGroupTotals
Regards,

Carles

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7227
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Clear the data of a card when leaving the stack

Post by jacque » Mon Nov 26, 2018 10:38 pm

cbarbal wrote:
Mon Nov 26, 2018 7:21 pm
Hi jacque,

The clearAllFinques handler and subhandlers
Thanks, but the puzzle remains. This:

Code: Select all

go card "Finques"
send "clearAllFinques" to card "Finques"
Should not require "send" or "call" because the card itself is current. If the datagrid is on that card, there should be no error "no such object". That makes me think the engine isn't really changing the focus to the current card. You should be able to just do this:

Code: Select all

go card "Finques"
clearAllFinques
Even so, "send" should work because it uses the context of the target card. "Call" should fail if you aren't on the current card because it uses the context of the card you're on, not the the card you're targeting. In Klaus' example, he's not only on the right card but also using "call" which is a double way of addressing the target card.

At any rate, the error probably isn't in the clearAllFinques handler, but in the subhandlers. I suspect LC isn't finding the datagrid for some reason (but that's the puzzle, since we're on that card already) and could possibly be fixed by using a long reference like "set the dgData of group "dgFinques" of card "Finques" to..." If you do that, you shouldn't even need to "go" to the card.

I don't think locking messages should be necessary.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Clear the data of a card when leaving the stack

Post by cbarbal » Tue Nov 27, 2018 12:39 pm

Hi,

The problem is the data grid. There is no way to erase it, I can give Yes 20 times and it does not even know. All other data grids can be deleted.
LiveCode001.jpg
There is some other way to erase it, or I have to make a new card. :(

Regards,

Carles

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Clear the data of a card when leaving the stack

Post by cbarbal » Tue Nov 27, 2018 7:32 pm

Hi Jacqueline,

I have created a new stack, cards "Menu" and "Finques". On a button on the card "Finques" has this handler, which works.

Code: Select all

on mouseUp
   clearAllFinques
end mouseUp
Out of the card if I do not put the call, he says he can not find the handler.

Code: Select all

on clearAllCards
   lock screen
   go card "Finques"
   call "clearAllFinques" of card "Finques"
   go card "Menu"
   unlock screen
end clearAllCards
This works only if it is in preOpenStack.

Code: Select all

on preOpenStack
   hide group "grpMenu"
   show button "btnConexio"
   clearAllCards
end preOpenStack
If I put it on the close button, it does not give an error but does nothing.

Code: Select all

on mouseUp
   closeConection
   clearAllCards
   close this stack
end mouseUp
Could not it be a bug?

Regards,

Carles

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7227
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Clear the data of a card when leaving the stack

Post by jacque » Wed Nov 28, 2018 10:39 pm

cbarbal wrote:
Tue Nov 27, 2018 7:32 pm
Hi Jacqueline,

I have created a new stack, cards "Menu" and "Finques". On a button on the card "Finques" has this handler, which works.

Code: Select all

on mouseUp
   clearAllFinques
end mouseUp
Out of the card if I do not put the call, he says he can not find the handler.
That's correct. It would probably help you understand more if you read about the message hierarchy in the User Guide. Messages are sent to objects in a specific order and are passed along a path until they reach the LC engine. Most messages are sent to the current card but are not sent to controls on that card. If a button generates a message then it will be caught by the group it is in, or by the card it is on. If you aren't on that card then the handler isn't available. If you put the handler into the stack script instead, it will be in the message path and the button will work if you change the handlers to use full object references (see below.)

Code: Select all

on clearAllCards
   lock screen
   go card "Finques"
   call "clearAllFinques" of card "Finques"
   go card "Menu"
   unlock screen
end clearAllCards
This works only if it is in preOpenStack.
This is similar to Klaus' suggestion and is part of the puzzle. If the first card of the stack is "Finiques" then you should not need the "call" command. If Finiques is not the first card then you do need it. But if you are using "call" then it should not matter where the commands are located. It should work with "call" from anywhere.

Code: Select all

on preOpenStack
   hide group "grpMenu"
   show button "btnConexio"
   clearAllCards
end preOpenStack
If I put it on the close button, it does not give an error but does nothing.
Right, because buttons do not receive messages generated by the LC engine. Most messages are sent to the card, so preOpenStack is not sent to the button at all.

Code: Select all

on mouseUp
   closeConection
   clearAllCards
   close this stack
end mouseUp
Could not it be a bug?
Where is the clearAllCards handler located? If it is in the card script and that card is the current card, then the button should work. If you want clearAllCards to work from anywhere, put it in the stack script and also put all the subhandlers in the stack script too. If you do that, you need to change all of the handlers to use a full object reference, such as: set the dgData of group "dgFinques" of card "Finiques" to ...

The message hierarchy is also discussed in the Scripting Conference stacks, here:http://www.hyperactivesw.com/revscriptc ... ences.html Once you know how messages are sent and received I think this will make more sense.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Clear the data of a card when leaving the stack

Post by cbarbal » Thu Nov 29, 2018 7:51 pm

jacque wrote:
If the first card of the stack is "Finiques" then you should not need the "call" command. If Finiques is not the first card then you do need it.
First card is "Menu", "Finques" is the second card
Where is the clearAllCards handler located? If it is in the card script and that card is the current card, then the button should work
The handler is in "Finques", but I throw it from the "Exit" button that is in the card "Menu"
The message hierarchy is also discussed in the Scripting Conference stacks, here:http://www.hyperactivesw.com/revscriptc ... ences.html Once you know how messages are sent and received I think this will make more sense.
In FileMaker all the scripts are together, it is as if they were in the stack script. And I can access from any layout (card), I have to think in terms of LiveCode, it's practical.

Thanks for the link, I've downloaded all Scripting Conference stacks

Regards

Carles

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”