third_party_content:community:commentary:revdevx:16416.3131365741

The Reflection API

Published 10 DEC 2012 at 07:30:55AM

Updated on 09 JUN 2022 at 07:30:55AM

From a tool-developers point of view one of the weaker areas in the Presentation Server has always been the lack of a "reflection API", i.e. a way to discover what properties, methods and events an object actually supports at runtime.  This in turn has led to creating manual lists and records of object attributes, bringing with it with the inherent difficulty of keeping this information up-to-date as new features are added. Primarily designed with the new PS-based Form Designer in mind, this shortcoming has been addressed in version 10 with the addition of the following new methods to the SYSTEM object:

  • REFLECTPROPERTIES
  • REFLECTMETHODS
  • REFLECTEVENTS

Each of these methods takes a single argument which is the type of object to query: e.g.

buttonProperties = exec_Method( "SYSTEM", "REFLECTPROPERTIES", "PUSHBUTTON" )
buttonMethods    = exec_Method( "SYSTEM", "REFLECTMETHODS", "PUSHBUTTON")
buttonEvents     = exec_Method( "SYSTEM", "REFLECTEVENTS", "PUSHBUTTON" )

Each method in turn returns a dynamic array of information describing the requested attribute type:

  • REFLECTPROPERTIES returns the name of each property and the type of the data it represents.  It also identifies the context that the property is valid for (Devtime/Runtime/Get/Set).
  • REFLECTMETHODS returns the name of each method, along with a list of arguments the method accepts and the type of data each argument should contain.
  • REFLECTEVENTS returns the name of each event the object type can raise along with the names and data types of arguments passed to an event handler.

Note that when these methods return the type of data for a property or argument there are some cases where only a broad hint is given - Basic+ is an untyped language so it is not really feasible to accurately describe some types using a simple set of flags - e.g. in the case where an argument is a complex dynamic array containing a variety of other core data types such a strings and numbers. Whilst aimed mainly at developers who write development tools for OpenInsight, this API may still be of interest for those of you who like to write your own diagnostic and debugging tools - when a new property, method or event is added to the Presentation Server it is clearly exposed thereby reducing the likelihood of it remaining hidden and undocumented. [Edit: 09 Jun 22 - Corrected method names (removed underscores)] [Edit: 24 Apr 13 - Call_Method renamed to Exec_Method] (Disclaimer: This article is based on preliminary information and may be subject to change in the final release version of OpenInsight 10).

Comments


At 04 JAN 2013 06:37PM Captain C wrote:

The SYSTEM object supports a TYPES property which lists all the objects supported by the Presentation Server (mentioned briefly in the earlier post on the new SYSTEM object properties).


At 04 JAN 2013 06:29PM Sprezz wrote:

How do we enumerate the supported objects?

Original ID: revdevx.wordpress.com/?p=283
  • third_party_content/community/commentary/revdevx/16416.3131365741.txt
  • Last modified: 2024/01/29 20:23
  • by 127.0.0.1