Page 1 of 1
reference of controls in a variable
Posted: Sun Jun 12, 2016 5:51 pm
by trevix
Someone can explain me why?
Code: Select all
on mouseUp
repeat with U = 1 to the number of controls of this card
put the abbrev ID of control U & cr after tListOfControls
end repeat
delete last char of tListOfControls
---THIS WORKS
put line 2 of tListOfControls into tAbbrevID
put word 2 of the short name of tAbbrevID into tNumber
--THIS ALSO WORKS
put word 2 of the short name of (line 2 of tListOfControls) into tNumber
--THIS DOEN'T WORK
put word 2 of the short name of line 2 of tListOfControls into tNumber
end mouseUp
Thanks
Trevix
Re: reference of controls in a variable
Posted: Sun Jun 12, 2016 6:08 pm
by FourthWorld
My tListOfControls may not be the same as yours. What is your line 2 that's causing the error to be thrown?
Re: reference of controls in a variable
Posted: Sun Jun 12, 2016 6:14 pm
by trevix
See the script of btn "Button One"
Re: reference of controls in a variable
Posted: Wed Jun 15, 2016 5:31 pm
by livecodeali
The reason is that there are 'chunk properties', for example:
Code: Select all
the backColor of line 2 of field 1
Without the brackets, tListOfControls is therefore being treated as a potential field reference, hence the "Chunk: error in object expression" error.
The brackets force
to be evaluated first, and then the whole thing is evaluated as a property of the resulting object, and similarly when it is put into a variable first.
The converse ambiguity can be seen if you have a field
line 1
line 2
which is selected, and executing
which will put empty rather than "line 2".
Re: reference of controls in a variable
Posted: Thu Jun 16, 2016 2:11 pm
by trevix
Sorry, but I have a hard time to understand.
Please see the attached stack. Is a simple script, to invert the top of two fields, using a var list. The purpose of the script is not important: what I am not sure to understand is how brackets seem to require a different approach along the script.
In one part of the script, this is saved correctly:
...
put item 1 of (line tLineOne of sChoiceList) into tTop
...
In another part of the script, if you take off the comment, trying to save it an error get reported:
...
put tReplacementTop into item 1 of (line tLineOne of sChoiceList)
...
also as error:
...
put tTop into (item 1 of line tLineTwo of sChoiceList)
...
Thanks for clarifying this to me
Re: reference of controls in a variable
Posted: Tue Jun 21, 2016 12:19 pm
by trevix
More on this...
On a script I have the following:
Code: Select all
repeat with U = 1 to 6 --line 1
put the abbrev ID of group ("FR_Process" && U) of me into tAbbrID --line 2
put (item 2 of (the loc of tAbbrID)) & comma & tAbbrID & cr after sChoiceList --line 3
end repeat
What happens is that on line 3 LiveCode simply stop executing, without reporting an error. Moving brackets around doesn't solve...
This also is not permitted:
put (item 2 of (the loc of tAbbrID of me)) & comma & tAbbrID & cr after sChoiceList
The thing gets fixed only doing this:
Code: Select all
repeat with U = 1 to 6 --line 1
put the abbrev ID of group ("FR_Process" && U) of me into tAbbrID --line 2
put (item 2 of (the loc of group ("FR_Process" && U) of me)) & comma & tAbbrID & cr after sChoiceList --line 3
end repeat
For what I know, ID should be unique in a stack and LC should know what they are.
I could use the long ID of the group, but the "background" word, from the dictionary, confuse me:
The long ID of a group includes the ID of the current card. If the group does not appear on the current card, requesting its ID causes an execution error. If you need to get the ID of a group, use the "background" terminology instead.
Beside the not reporting of an error, I don't remember to ever have these kind of problems on older versions of LC. It is like if LC scrambles its internal list of things.
Thanks for any help.
Re: reference of controls in a variable
Posted: Wed Jul 13, 2016 4:53 pm
by trevix
Also, this does not works:
Code: Select all
--button on card 1
on mouseUp
put the abbrev ID of group "GroupOne" of group "GroupTwo" of card 2 into tAbbrevID
put "something" into fld "TextField" of tAbbrevID of group "GroupTwo" of card 2
end mouseUp
No brackets are allowed on the IDE. How can it be solved?
Trevix
Re: reference of controls in a variable
Posted: Sat Jul 23, 2016 9:30 am
by trevix
Some one can clarifying me why the above example doesn't work?
Thanks
Re: reference of controls in a variable
Posted: Sat Jul 23, 2016 7:45 pm
by [-hh]
An abbrev ID can not be used to build a 'longer' object identification.
Just use the long ID for that. [Or build the string and use "do".]
You could try:
Code: Select all
on mouseUp
put the abbrev ID of group "GroupOne" of group "GroupTwo" of card 2 into tAbbrevID
put "something" into fld "TextField" of tAbbrevID -- works if the ID of the group is unique
end mouseUp
But the long ID is of the form: group ID 42 of card ID 13 of stack "myTest.livecode"
As long as you don't use a group that isn't place on any card, this should work:
Code: Select all
on mouseUp
put the long ID of group "GroupOne" of group "GroupTwo" of card 2 into tLongID
put "something" into fld "TextField" of tLongID
end mouseUp
Re: reference of controls in a variable
Posted: Mon Jul 25, 2016 11:56 am
by trevix
Thanks for answering.
I knew of course about long ID, but this wasn't my point.
I wrongly supposed that, once the correct default stack is set and in that stack there is a control with that abbrev ID, being the ID unique, LC would know about it and it's path.
So, this is not true?
Re: reference of controls in a variable
Posted: Mon Jul 25, 2016 1:03 pm
by SparkOut
It seems natural to me to expect that a variable can be used to resolve object id/names. I think it's irrelevant whether the id is or isn't unique, if the object reference has been resolved correctly.
There is definitely something wrong in this scenario though.
For instance:
Code: Select all
--button on card 1
on mouseUp
put the long ID of group "GroupOne" of group "GroupTwo" of card 2 into tLongID
put the abbrev ID of group "GroupOne" of group "GroupTwo" of card 2 into tAbbrevID
put the short ID of group "GroupOne" of group "GroupTwo" of card 2 into tShortID
put "something long" into fld "LongField" of tLongID -- works
put "something short" into fld "ShortField" of group id tshortID of group "GroupTwo" of card 2 -- works
put "something abbrev" into fld "AbbrevField" of tAbbrevID of group "GroupTwo" of card 2 -- fails with execution error (Chunk: can't find background)
end mouseUp
--button on card 2
on mouseUp
put the long ID of group "GroupOne" of group "GroupTwo" of card 2 into tLongID
put the abbrev ID of group "GroupOne" of group "GroupTwo" of card 2 into tAbbrevID
put the short ID of group "GroupOne" of group "GroupTwo" of card 2 into tShortID
put "something long" into fld "LongField" of tLongID -- works
put "something short" into fld "ShortField" of group id tshortID of group "GroupTwo" of card 2 -- works
put "something abbrev" into fld "AbbrevField" of tAbbrevID of group "GroupTwo" of card 2 -- populates the field correctly but then fails with execution error (Chunk: source is not a container)
end mouseUp
It looks like a bug submission is in order
Re: reference of controls in a variable
Posted: Mon Jul 25, 2016 2:12 pm
by trevix
Submitted Bug 18080
Thanks SparkOut
Trevix
Re: reference of controls in a variable
Posted: Mon Jul 25, 2016 3:37 pm
by [-hh]
Hi all.
what I meant is that this cannot work as long there is a chance for the engine to interpret "tAbbrevID" as variable containing the string "group id 42" of "field id 42".
For "put":
We can use it to build an identifier string and then use "do" but we can't use it as part of an object identifier.
For "set <prop>" or "get <prop>":
Use it as object identifier (but not as 'beginning' part of a longer object identifier).
Code: Select all
on mouseUp
put the abbrev id of fld 1 into tAbbrevID
put "abcdefg" into h
-- put h into tAbbrevID -- puts h into the variable tAbbrevID <----
do "put h into" && tAbbrevID -- puts correctly h into fld 1
set text of tAbbrevID to (h&h) -- works
set backcolor of tAbbrevID to "black" -- works
put the text of tAbbrevID into fld 2 -- works
end mouseUp
Re: reference of controls in a variable
Posted: Mon Jul 25, 2016 5:26 pm
by trevix
I understand that.
But here one more example
Code: Select all
on mouseUp
put the abbrev ID of group "GroupOne" of group "groupTwo" into tAbbrevID
put "something abbrev" into fld "AbbrevField" of tAbbrevID --THIS WORK
put "something abbrev" into fld "AbbrevField" of tAbbrevID of group "GroupTwo" --THIS DOESN'T WORK
end mouseUp
Notice that the first time I mistakenly called both groups "groupTwo", I've got an error such:
button "Button": execution error at line 2652 (Handler: can't find handler) near "moveStack", char 1 --(!?)
Re: reference of controls in a variable
Posted: Mon Jul 25, 2016 6:23 pm
by [-hh]
Hi trevix,
I see your problem. I had also similar problems in situations that were not this 'deep' (obj of group of group) as yours. I try to understand it this way.
- The engine interprets the first word of the content of a variable after "of" as object type, if the variable is the end of descriptor:
' .. of tAbbrevID' works.
- The engine doesn't accept a variable after "of" that is followed by other object descriptions, it expects then an object type:
'.. of tAbbrevID of group "GroupTwo" ' doesn't work.
This may have reasons in that such a "resolving" parsing could lead to a too deep (if not endless?) parsing loop.
p.s. The error reporting you denote is of course worth a "funny" bug report
