Changing a Field's contents when a global variable is changed

Jim Ault JimAultWins at yahoo.com
Mon Mar 5 16:52:38 EST 2007


On 3/5/07 10:34 AM, "Len Morgan" <len-morgan at crcom.net> wrote:

> Is there a way to have the contents of a field on a card change when a
> global variable (in this case an array variable) is changed?
> 
> I have a multiple card application that I'm converting from Tcl.  One of
> the things I like about Tcl is that a field has a parameter called
> -textvariable) that points to a location that holds the contents to be
> displayed in that field.  If you change the contents of the field, what
> you are really changing is the global variable and vis-versa.  This
> allows me to put a field on several cards (in different locations on
> each card) and when I read a new record, I just put the results into a
> global array.  I'd like to try and do the same thing in Rev if it's
> possible.
> 
> I'd like to avoid writing a script in the "readrecord" function that has
> to know the names of every field on every card that needs to show that
> information, and then looping through and setting the text of each of
> those fields to the contents of the global variable.  This seems like it
> would be very hard to maintain system.

It sounds like you are using different field names on each card, and not
using groups to work with layouts.  Also, it sounds like you are using each
card to be a different layout for the user benefit. If this is the case,
then......

There are ways of doing the task you outline very efficiently, but not using
the same simple mode of Tc1, which is similar to several Excel formulas
linking one value to may locations.

First part - You can use a single global for each value, but better to use a
list format for all of your record fields.  My preference would be to read
the data record into an array variable, set the customproperties of this
stack to that array variable. (see why below)

The basic handlers you would write to make updating automatic are in the
stack script:

on populateAllRecordFlds
  put the customproperties of this stack into tempList
  combine tempList using cr and tab
  --now you have a table of property names and values
  --eg.  (where ^ is the tab char)
  --rcdTime^2:49 PM
  --rcdDate^2/20/07
  --rcdDescription^Last update session
  --rcdTitle^Planning Meeting Notes
  --updateTimeStamp^11223441232
  
  filter tempList with "rcd*"
   --now you only  have the values
   --you care to update
   
   replace "rcd" with empty in tempList
  set the itemdel to tab
  repeat for every line LNN in tempList
    --LNN is a var that contains the entire line
    put item 1 of LNN into fldName
    do "put "& item 2 of LNN & " into fld "& fldName
  end repeat
  
end populateAllRecordFlds

--then you can
on opencard
  --for this card only
  populateAllRecordFlds
end opencard

on retrieveRecord
  --do the retrieve stuff here
  populateAllRecordFlds
end retrieveRecord

on closefield
    --update Array
end closefield

My preferred method would be to use a stack custom property since globals
are actually global to the Rev environ, not just the stack.  The same global
name used by any other stack would declare and update the same global.

Hope this helps

Jim Ault
Las Vegas





More information about the use-livecode mailing list