using arrays in custom properties

Jan Schenkel janschenkel at yahoo.com
Mon Mar 10 06:30:01 EST 2003


--- Ben Rubinstein <benr_mc at cogapp.com> wrote:
> I'm storing an array in a custom property of an
> object.  Storing and
> retrieving items is fine.  But I'm having no luck
> wiping them.
> 
> Let's say that I've got a price list object, and I
> want to have a custom
> property array linking 'specials' to their special
> prices.  One day fruit is
> on special offer:
> 
>     put "23.99" into the specialPrices["Bananas"] of
> btn "PriceChecker"
>     put "9.99" into the specialPrices["Apples"] of
> btn "PriceChecker"
> 
> The next day, vegetables are on offer:
> 
>     put "5.50" into the specialPrices["Potatoes"] of
> btn "PriceChecker"
>     put "5.99" into the specialPrices["Turnips"] of
> btn "PriceChecker"
> 
> Now if I inspect the custom property
> 'specialPrices', it has all four items
> listed, when I really only wanted the most recent
> two.
> 
> I want a way that I can start afresh, without caring
> what went before.  If
> specialPrices was a global variable, I can wipe out
> the array by doing:
>     put empty into specialPrices
> 
> or even
>     delete variable specialPrices
> 
> How can I do something similar in the case of a
> customProperty which is an
> array?  If I tried 
>     put empty into the specialPrices of btn
> "PriceChecker"
> 
> ...I would just create a new item in the
> 'customKeys' array, with key
> "specialPrices", value empty.  The "specialPrices"
> array would be unchanged.
> 
> If I tried
>   delete variable the specialPrices of btn
> "PriceChecker"
>   delete variable specialPrices of btn
> "PriceChecker"
>   delete the specialPrices of btn "PriceChecker"
> 
> ... I would (did!) get a syntax error.
> 
> If I know the keys of the specialPrices array, I
> could at least put empty
> into each one, which is sub-optimal but still not
> too bad... but I haven't
> even found the syntax for that.  It's not:
>   put the keys of the specialPrices of btn
> "PriceChecker"
> 
> All help gratefully received!
> 
> TIA,
>  
>   Ben Rubinstein

Hi Ben,

Have a look at the following entries in the Transcript
Dictionary:
- customProperties
- customPropertySet

Here's what I would do in your case :

  -- setup the keys you want to keep
  put "Potatoes,Turnips" into tGoodKeys
  -- switch the customPropertySet
  set the customPropertySet of btn "PriceChecker" to \
      "specialPrices"
  -- retrieve the keys
  put the customProperties into tOldProperties
  put the keys of tOldProperties into tOldKeys
  repeat for each line tKey in tOldKeys
    -- check if we want to keep
    if tKey is among the items of tGoodKeys then
      put tOldProperties[tKey] into
tNewProperties[tKey]
    end if
  end repeat
  -- update the customProperties of this set
  set the customProperties of btn "PriceChecker" to \
      tNewProperties
  -- reset the customPropertySet of the btn
  set the customPropertySet of btn "PriceChecker" to \
      empty
  -- now add the other specialPrices[] properties
  -- ...

Hope this helped,

Jan Schenkel.

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/



More information about the use-livecode mailing list