Page 1 of 1

Referencing objects

Posted: Wed Sep 09, 2015 8:09 pm
by kolia
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

Re: Referencing objects

Posted: Wed Sep 09, 2015 8:23 pm
by dunbarx
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.

Re: Referencing objects

Posted: Wed Sep 09, 2015 8:23 pm
by FourthWorld
In the Dictionary see the "defaultStack" global property.

Re: Referencing objects

Posted: Thu Sep 10, 2015 4:50 pm
by kolia
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

Re: Referencing objects

Posted: Thu Sep 10, 2015 5:19 pm
by Klaus
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

Re: Referencing objects

Posted: Thu Sep 10, 2015 5:31 pm
by kolia
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

Re: Referencing objects

Posted: Thu Sep 10, 2015 5:36 pm
by Klaus
Hi Nicolas,

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


Best

Klaus