properties vs local variable
J. Landman Gay
jacque at hyperactivesw.com
Mon Mar 10 12:46:22 EDT 2014
On 3/10/14, 7:15 AM, Terence Heaford wrote:
> repeat for each item tCellData in tFldData
> put tCellData into fld tFldNum of me
> set the backgroundColor of fld tFldNum of me to tBackColor
> set the foregroundColor of fld tFldNum of me to tForeColor
> add 1 to tFldNum
> end repeat
This will be the speed bottleneck. Array access is very fast, faster
than almost any other method. As noted here, variable access is the
fastest, followed by access to custom properties, but the difference is
so minimal as to be insignificant. But manipulating field content is one
of the slowest things a script can do, for several reasons. So whenever
possible, you need to minimize the number of times a script accesses a
field.
Locking the screen as you did to prevent redraw lag is a good start.
That's sometimes enough for a small number of updates. If it isn't, grab
the field content, manipulate it all at once, and then put it back.
Since colors can only be applied directly to fields, you can't
manipulate those in variable. But you can create htmltext and then set
the field's htmltext at one go. In this case that's what I'd do. To get
proper html for the field, just manually set up the field colors once
and put the field's htmltext into the message box. Use that text as a
template to script the changes. I frequently store template htmltext as
a custom property of the field, with merge markers ("[[tBackColor]]").
Then when I need to update the htmltext, I use the merge command. It's a
one-liner and very fast.
I think if you use this method you will notice a dramatic increase in speed.
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list