Page 1 of 1

Add new properties without blowing up existing

Posted: Sat Dec 15, 2018 8:10 pm
by pink
Okay, so here's my next problem... I updated a widget that I've been using in projects and added a property:

Code: Select all

property showTitle       get mShowTitle      set setshowTitle
metadata showTitle.editor      is "com.livecode.pi.boolean"
metadata showTitle.default     is "false"
metadata showTitle.section     is "Text"
private variable mShowTitle as Boolean

private handler setshowTitle(in pVal as Boolean)
    put pVal into mShowTitle
   redraw all
end handler
added the following to OnSave:
put mShowTitle into rProperties["showTitle"]

added the following to OnLoad:
put pProperties["showTitle"] into mShowTitle

The problem is, that when I open a stack that uses this widget, it errors out at the line in "OnLoad" because the "showTitle" key does not currently exist. How do I get around this?

Re: Add new properties without blowing up existing

Posted: Sat Dec 15, 2018 9:10 pm
by [-hh]
That's what I called "make downward compatible":
viewtopic.php?p=174057#p174057

Code: Select all

public handler OnLoad(in pP as Array)
   if <key> is among the keys of pP then
   -- do something
   else
   -- set a default value if not already set with the property definition
   end if
end handler

Re: Add new properties without blowing up existing

Posted: Sat Dec 15, 2018 9:24 pm
by pink
Okay, that is what I needed... should've read that closer...