what is the method you use to save a specific field reference in a variable or custom property?

Ken Ray kray at sonsothunder.com
Tue Sep 12 22:04:50 EDT 2006


On 9/12/06 7:55 PM, "Josh Mellicker" <josh at dvcreators.net> wrote:

> Maybe someone can shed some light on the best way to put a field
> reference into a variable (or custom property).
>
> So my question is, what is the method you use to save a specific
> field reference in a variable or custom property?

Well, saving the reference is easy (I recommend the long id) ;-) using it is
another matter. Although there are instances where you can use the object
reference itself, sometimes you can't and will get an error - for example,
with fields, you can set direct properties (the lockText of tFld, the
showBorder of tFld, etc.), without getting an error, but chunk expressions
will work on the variable itself and not on the reference. Compare:

  -- assume that fld 1 has 3 lines of text
  put the long id of fld 1 into tFld
  set the lockText of tFld to true
  --> works as expected, sets the lockText of the field

  put the the number of lines of tFld
  --> 1   -- since tFld is a fld ref and a single line of text, it returns 1

So to get around this, you need to use "do" in some instances:

  do "put the number of lines of" && tFld
  --> 3

Additionally if you use "put", it's not the same as if you'd addressed the
field directly. Compare:

  put fld 1
  --> puts the contents of fld 1

  put tFld
  --> puts the field reference to field 1

  do "put" && tFld
  --> puts the contents of fld 1

  put the text of tFld
  --> puts the contents of fld 1

Personally I use "do" whenever *not* not using it fails - I don't think
there's a downside to always using "do" when you have a long ID as a
reference, other than that it takes slightly longer to process because it
needs to interpret it on the fly (which really only shows itself when you
have it in a loop).

HTH,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com





More information about the Use-livecode mailing list