Page 1 of 1

Scope of Controls

Posted: Mon Apr 14, 2014 8:13 am
by Simon Knight
I am working on a simple application which was working fine until I added a second card. The application has most of the routines written in the stack. I started with two data grids on the first card and all was well. I decided to move one of the datagrids to a new second card and now I am having problems writing data to it.

After much running around in circles I have decided that I am attempting to write to controls (datagrid) that are out of scope and because of their complexity datagrids do not fail in the same way that simple controls do.

The code snip below fails to write to a datagrid that is on card 2 of the stack and is not displayed as card 1 is being displayed when the script is run.

Am I correct in thinking that a handler in the stack will default to searching the current card or do they just default to card 1 of stack. i.e. if I write the short code :

Code: Select all

set the dgText[false] of grp "DgDuplicates"  to sTestData
is the engine actually adding a "of card 1" or "of the current card" to the call. Looking at the message path diagrams it would seem that a handler in a stack should never find a control on a card, yet they do.

best wishes

Simon K

Re: Scope of Controls

Posted: Mon Apr 14, 2014 11:10 am
by Klaus
Hi Simon,

the engine will always look at the current card if you do not supply an other descriptor for an object!


Best

Klaus

Re: Scope of Controls

Posted: Mon Apr 14, 2014 5:57 pm
by dunbarx
Hi.

Do you see what Klaus meant? You asked the question in a way that indicated to me you already knew the answer, but thought that answer was somehow unusual or inappropriate. I hope by now you tried this:

Code: Select all

set the dgText[false] of grp "DgDuplicates"  of cd 2 to sTestData
This is sometimes essential, because many stacks have background groups on multiple cards, but the data in each of those cards is (generally) unique to those cards. So you can:

add fld 3 of cd 5 to fld 5 of cd 3

or

answer fld 2 of cd 2 + fld 3 of cd 3

I take the easy way out all the time, when I know the controls on the current card will suffice for the task. But it is not crazy to ALWAYS place the card reference in your code, just as a matter of style. The important thing is to know this is an issue, or rather, a feature.

Craig Newman

Re: Scope of Controls

Posted: Fri Apr 18, 2014 10:12 pm
by Simon Knight
Thanks for confirming what is happening and how Livecode operates. I have to pay greater attention when moving or copying objects between cards and stacks. As to knowing the answer when I posted the question, well it sort of slowly revealed itself.