Scope of Controls

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
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Scope of Controls

Post by Simon Knight » Mon Apr 14, 2014 8:13 am

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
best wishes
Skids

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Scope of Controls

Post by Klaus » Mon Apr 14, 2014 11:10 am

Hi Simon,

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


Best

Klaus

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

Re: Scope of Controls

Post by dunbarx » Mon Apr 14, 2014 5:57 pm

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

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Scope of Controls

Post by Simon Knight » Fri Apr 18, 2014 10:12 pm

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.
best wishes
Skids

Post Reply