curiosities in object reference
Richard Gaskin
ambassador at fourthworld.com
Tue Apr 21 09:58:20 EDT 2015
Peter M. Brigham wrote:
> It seems to depend entirely on the context of the command.
> If the engine sees something that can only be done to an
> object reference, it resolves the reference. If it doesn't,
> it treats it as an ordinary container with a text string
> content.
This was a mental challenge for me for many years across all the xTalks
I've worked with. Thankfully LiveCode offers a broad range of
property-oriented syntax to work with container objects, so as a rule I
tend to favor things like this:
set the text of tFieldObj to "Hello World"
...over using "put":
put "Hello World" into tFieldObj
...which of course will merely do exactly what I'm telling it to do (put
a value into a variable), which many not be what I mean (put a value
into an object referred to in a variable). :)
Since only objects have properties and strings don't, when using
property settings for content manipulation the engine will never guess
wrong about what it's supposed to do with tFieldObj.
One nice thing that's unique to LiveCode among all xTalks is its
htmlText property, which allows us to faithfully reproduce all content
and styling for field objects, and can be used for a portion of field
objects:
set the htmlText of word 2 of line 3 of tFieldObj \
to "<b>Hello World</b>"
And if styling isn't needed, the text property can be used just as flexibly:
set the text of word 2 of line 3 of tFieldObj \
to "Hello World"
When "set the text of..." is cumbersome (when you're working with lots
of fields), you can use any string in which at least part of the object
reference is hard-coded:
put "Hello World" into field tMyFieldName
I haven't read the User Guide section on working with containers in a
long time - anyone here have an opinion on how clearly it treats object
references? Might be nice to have the docs team clean that up if it
includes any examples which are ambiguous at runtime.
--
Richard Gaskin
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
____________________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list