Referencing objects

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kolia
Posts: 82
Joined: Thu May 28, 2015 3:53 pm

Referencing objects

Post by kolia » Wed Sep 09, 2015 8:09 pm

Hi,
I have a card in a substack where I store several parameters. In the main stack I use this instruction to set a variable

Code: Select all

put "field "User" of stack "Parameters" & field "IPAddress" of stack "Parameters" & field "Password" of stack "Parameters" into response
I was wondering if there a way to set a temporary context what would allow to avoid the repetition of "of stack "Parameters" in this example.
Thank you
Nicolas
LC 7.1 on Windows 8.1 and on MAC OS 10.10.5 Xcode 6.4 - 7.1

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

Re: Referencing objects

Post by dunbarx » Wed Sep 09, 2015 8:23 pm

Hi.

Well, yes and no.

The "no" is that if you are in one stack, you need a fairly explicit pathname to an object in another stack. The "yes" is something like this:

Code: Select all

go stack "parameters"
get fld "user" & fld "IPAddress" & fld "password"
Another form of "yes", and much more robust if you are going to be doing this sort of thing a lot, is to place the contents of each field into a custom property. For example (pseudo):

Code: Select all

on closeField
put me into customPropertyNameBasedOnNameOfField
These properties might be updated every time a field is changed, using a "closeField" handler residing in the card script, and referencing each field via "the target" function. Anyway, you could then simply:

Code: Select all

get theUserField & theIPAddressField & thePasswordField
Where the location of the user is no longer an issue of any kind. Write back if none of this is clear.

Craig Newman

EDIT:

I was too quick. The custom properties would still have to reference the objects to which they are attached:

Code: Select all

get theUserField of field "users" of stack...
So there is little advantage. The other way to do this, using global variables, would require no such reference. They could be loaded as I mentioned before, in a card level closeField handler. But almost everyone shies away from these. You would have to declare them in the operative handler, so, again, another layer of annoyance. Maybe, after all, method 1 is cleanest.
Last edited by dunbarx on Wed Sep 09, 2015 10:19 pm, edited 6 times in total.

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

Re: Referencing objects

Post by FourthWorld » Wed Sep 09, 2015 8:23 pm

In the Dictionary see the "defaultStack" global property.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kolia
Posts: 82
Joined: Thu May 28, 2015 3:53 pm

Re: Referencing objects

Post by kolia » Thu Sep 10, 2015 4:50 pm

Hi Craig,
I got the picture. May be there is no need to have a card in another stack. Let me explain you what I'm currently doing.
I have a card in the main stack that turns to be the main user interface. I have a second card to store several persitent parameters. I noticed that the size of the second stack is the same as the first one, which I don't wan't. So I resized this second stack which resized the first one (that I don't wan't :wink: )
So either there is way to stop the inherit mecanism, either I use a sub stack, and may the best solution, would be store parameters in the mainstack propoerties.

Let me know
Thanks
Nicolas
Nicolas
LC 7.1 on Windows 8.1 and on MAC OS 10.10.5 Xcode 6.4 - 7.1

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

Re: Referencing objects

Post by Klaus » Thu Sep 10, 2015 5:19 pm

Hi Nicolas,

well, stack size = card size, that's the way LC works :D

If you want to have different sized cards in the same stack
you need to change the dimensions of the cards on "preopenstack"
and resize the stack back on "closecard".
Know what I mean?

But why not store your data in custom properties of your stack?
...
set the cData1 of this stack to "some data here..."
...
and retrieve it like:
...
put the cData1 of this stack into fld XYZ
## or whatever...
...
You should of course use more meaningful names for your custom properties :D


Best

Klaus

kolia
Posts: 82
Joined: Thu May 28, 2015 3:53 pm

Re: Referencing objects

Post by kolia » Thu Sep 10, 2015 5:31 pm

If you want to have different sized cards in the same stack
you need to change the dimensions of the cards on "preopenstack"
and resize the stack back on "closecard".
Know what I mean?
I got it
And indeed I will store those parameters in the stack properties.
Thanks for your invaluable time and advise
Nicolas
Nicolas
LC 7.1 on Windows 8.1 and on MAC OS 10.10.5 Xcode 6.4 - 7.1

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

Re: Referencing objects

Post by Klaus » Thu Sep 10, 2015 5:36 pm

Hi Nicolas,

you're welcome!
I cannot live without custom properties anymore, once I "got" them, which took a while! :D


Best

Klaus

Post Reply