Accounting for new widget properties in an OnLoad handler

When writing a LIveCode widget the OnLoad handler is used to populate variables in the current instance of the widget with values that were stored with the widget. Version 1 of an OnLoad handler looks something like this:

public handler OnLoad(in pProperties as Array)
   put pProperties["text"] into mText
   put stringToColor(pProperties["text color"]) into mTextColor
   put stringToColor(pProperties["button color"]) into mButtonColor
end handler

Now assume that you released this widget and there are stacks using it. You then decide that you want to add some more properties to the widget. You make the necessary changes to your OnLoad handler so that version 1.0.1 looks like this:

public handler OnLoad(in pProperties as Array)
   put pProperties["text"] into mText
   put stringToColor(pProperties["text color"]) into mTextColor
   put stringToColor(pProperties["button color"]) into mButtonColor

   // New properties added in version 1.0.1
   put stringToColor(pProperties["border color"]) into mBorderColor
   put pProperties["stroke width"] into mStrokeWidth
end handler

You compile the widget and then launch your project. When your existing widgets are displayed on the screen they aren’t rendered. All you see is an empty area. You try to check the properties in the property inspector but no properties are set. What is going on?

Since your widgets created with version 1 of your widget they didn’t store any properties named “border color” or “stroke width”. When you try to access a key of the pProperties array that doesn’t exist LCB is unhappy and refuses to go on.

There is an easy fix, however. Whenever you release a new version of your widget with new properties you need to add a check to make sure the new properties are keys in the pProperties array.

public handler OnLoad(in pProperties as Array)
   put pProperties["text"] into mText
   put stringToColor(pProperties["text color"]) into mTextColor
   put stringToColor(pProperties["button color"]) into mButtonColor

   // New properties added in version 1.0.1
   if "border color" is among the keys of pProperties then
      put stringToColor(pProperties["border color"]) into mBorderColor
      put pProperties["stroke width"] into mStrokeWidth
   end if
end handler

Since I added “border color” and “stroke width” in version 1.0.1 I just check for the presence of one of the keys. If one of the keys is present then the other will be present as well.

With this change to the code, your existing widgets will still load when running with version 1.0.1 of your widget.

Creating a Busy Indicator in LiveCode Builder

One of my favorite aspects of creating Widgets with LiveCode Builder (LCB) is that I don’t have to create multiple image assets in order to support various display resolutions. Since it is possible to create very complex shapes using the new drawing routines I no longer have to resort to using PNG images exported from Photoshop for more complicated aspects of my UI.

Busy indicators are one control in particular that are quite a pain to manage. You needed to generate a PNG image for each frame in the animation and you had to create the animation for at least two sizes (1x and 2x). With widgets creating a busy indicator is much simpler and you get better results. Here are a couple of notes from a busy indicator that I just finished working on. You can get the source from my livecode-extensions github repository.

Continue reading

Dawn of the Planet of the Widgets

On March 12th Kevin Miller announced the first LiveCode 8 developer preview at the LiveCode Unconference in Brooklyn. At the heart of the announcement was the introduction of widgets, a new control available to LiveCode developers. Thanks to the LiveCode Github respository, I had been using LiveCode 8 in the weeks leading up to the announcement. As LiveCode engineers made improvements I would update my local repository, rebuild using Xcode, and test. I was so impressed with what I saw that I decided to move a project I’ve been working on for the last few months to version 8 right away. Why would I trust my project to a LiveCode engine that hadn’t even reached a public beta yet? Let’s take a look.

Continue reading

Using SourceTree to monitor progress on LiveCode

When LiveCode became open source after the Kickstarter campaign all of the source code was moved to Github. Because the livecode repository on Github is public, you can monitor all changes which are submitted to it.

I’m going to show you how to easily monitor progress on the LiveCode engine using SourceTree, a free Git client for Mac and Windows made by Atlassian.

Continue reading

A Plugin For Monitoring the focusedObject

Knowing which object currently has focus can help you troubleshoot situations when messages aren’t being sent to the object you think should be getting them. I have a plugin I use called ReportTheFocusedObject which continually monitors the focusedObject and selectedField so that you can quickly determine which object is the target of messages.

You can download the plugin here.

For instructions on how to install plugins for Revolution see this lesson.

RunRevLive 09 Resources

I took down the original page of links to my session materials that  I posted for the RunRevLive 09 conference so I’m reposting the content here.

Behaviors and Custom Controls

Behavior Helper Plugin

http://www.bluemangolearning.com/download/revolution/tools/BehaviorHelper.rev.zip

Custom Control Helper Plugin

http://www.bluemangolearning.com/download/revolution/tools/CustomControlHelper.rev.zip

Behaviors & Custom Controls Stacks

http://www.bluemangolearning.com/download/revolution/tools/behaviors_customcontrols.zip

Instructions Showing How To Install a Plugin

http://revolution.screenstepslive.com/spaces/revolution/manuals/plugins/lessons/5489-Installing-the-Plugin

Password Font

http://www.bluemangolearning.com/download/revolution/tutorials/passwordentry.zip

Presenting Data with the Data Grid

Data Grid Sample MP3 Library

http://www.bluemangolearning.com/download/revolution/tools/data_grid_sample_mp3_library.zip

Creating a Music Library Interface Part I

http://revolution.screenstepslive.com/spaces/public_staging/manuals/740

SQL Yoga 1.0.1 Released with New IDE Plugin


New Features and Bug Fixes

SQL Yoga 1.0.1 is now available for immediate download from the SQL Yoga site. The new version has a number of bug fixes as well as some new features.

Two new time-saving commands have been added to the library that will speed up creating and updating records:

Both of these commands allow you to pass in arrays with the values you want to insert/update in the database.

For a full list of changes please see the change log.

New Plugin

A new IDE plugin is now included with the SQL Yoga distribution. The plugin automates a few tasks and provides logging. You can read about how to install and use the plugin in the new plugin manual.

Learn More

To learn more about SQL Yoga, download a demo or purchase please visit the SQL Yoga page.

RunRev MegaBundle: Get $4000 of software for $499

RunRev is offering their MegaBundle sale again this year. This is your best chance to get all of the tools you need for a great price.

RunRev MegaBundle 09

If you just need to renew your revEnterprise license or have been looking at developing software with Revolution this is the best price you are going to get.

All of our products that are available through RevSelect are included with the bundle: SQL Yoga, Professional Application Development with Revolution training courses and ScreenSteps standard.

http://www.runrev.com/products/mega-bundle-09/