Add new properties without blowing up existing

Moderators: LCMark, LCfraser

Post Reply
pink
Posts: 252
Joined: Wed Mar 12, 2014 6:18 pm

Add new properties without blowing up existing

Post by pink » Sat Dec 15, 2018 8:10 pm

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?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2123
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Add new properties without blowing up existing

Post by [-hh] » Sat Dec 15, 2018 9:10 pm

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
shiftLock happens

pink
Posts: 252
Joined: Wed Mar 12, 2014 6:18 pm

Re: Add new properties without blowing up existing

Post by pink » Sat Dec 15, 2018 9:24 pm

Okay, that is what I needed... should've read that closer...
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Post Reply

Return to “LiveCode Builder”