Arrays and custom properties

Monte Goulding monte at sweattechnologies.com
Mon Aug 4 22:44:00 EDT 2003


>
> I am struggling with the concept of arrays and custom properties and am
> looking for a cookbook example.
>
> Let's say I want to make something like the included Employee Database
> example that comes with Rev. It makes a new card for each record but I
> don't want to do that, I want to put the information in an array and
> store it in a custom property. This will allow me to have complex
> information in a field such as TABS, RETURNS, and maybe formatting in a
> field (like a notes field) and encrypt the data by password protecting
> the stack.
>
> My problem is that I don't know how to actually code it. Here is a
> simple scenario:
> 1. Stack named "Company Directory" as a standalone
> 2. Stack named "CDData.rev" where the data will be stored in a custom
> property
> 3. Card named "Employees" with 4 fields
> 	FirstName
> 	LastName
> 	Notes
> 	Index (to show all of the records in a list field. Click on
> the item
> to populate the other fields.)
>
> All of the data will be in an array which is read from or written to
> the custom property.
> 1. The array is modified when records are added, deleted, or changed.
> 2. The array is saved to the CDData.rev stack in a custom property when
> the item is changed.
> 3. Upon opening the standalone, data is read from the custom property
> which is then put into the Index field.
>
> How would I do this? I think it is likely to be simple but I am unclear
> on the execution.
>
Hi Bill

The way I would go about it is to use a customPropertySet as a two
dimensional array. The first dimension is your field names FirstName,
LastName, Notes. The second dimension is your record number 1,2,3....

There are a number of item delimiters you could use ,|./ etc but the only
one that is supported by the rev IDE is _ so the keys of your
customPropertySet will look like FirstName_1,FirstName_2 ... etc

Create 1 card to be your interface to the data. Create another to be an
index. To show record 1 you would do the following:

put the customKeys["uCDData"] of stack "CDData.rev" into tCDDataKeys
filter tCDDataKeys with "*_1"
set the itemDel to "_"
repeat for each line tLine in tCDDataKeys
  put the uCDData[tLine] of stack "CDData.rev" into fld item 1 of tLine
end repeat

Then you could set the uCurrentRecord of the stack to 1
Then on closeField you could update the record like this:

repeat for each item tItem in "FirstName,LastName,Notes"
  put tItem&"_"&the uCurrentRecord of this stack into tSet
  set the uCDData[tSet] of this stack to fld tItem
end repeat

I'm sure you can work out how to populate the index.

Cheers

Monte




More information about the use-livecode mailing list