About the Newlook Object Model

Newlook has an internal object model which can be used to manipulate and examine objects such as Forms, Controls and the Application window.

Objects

An object is a piece of your application, like a form or a control, while a collection is a group of related objects. An object may contain any number of properties, events or methods, or it may not contain any at all. Some objects and collections always exist in Newlook. These are the App, Clipboard, Http, ThisSession and System objects, and the Sessions collection. Other objects and collections are created and destroyed dynamically by Newlook. For example, every time a screen is received from the host a form object is created that represents this screen. Similarly, every time a control is created on a form, an object is also created that represents this control and allows scripts and macros to interact with the control programmatically. The object representing the control is a member of the Controls collection of the Form object that it belongs to. Likewise, all open forms are members of the Forms collection of the App object. It is worth noting that Active Form is a child of the App object and any controls on your form will be children of either the active form or your master form (if you have enabled one for your solution).

Within the Newlook object model, there is an object hierarchy with the Sessions collection at the root. Each running session in Newlook has it's own System, App, http, Clipboard objects and any variables created in that session.

To view the Newlook object model hierarchy, open Inspector (Tools | Inspector or Ctrl+Shift+i in the Runtime client menu) and expand the object model tree.

You will notice that, even though the Sessions collection is the root of the Newlook object model, the App, Clipboard, Http, System and ThisSession objects also exist at the same level. These top level objects in Inspector relate to the session that is active at the time Inspector is opened. They provide backwards compatibility for solutions that were developed before the introduction of the Sessions collection.

Properties

Objects generally have properties. A property has a name and a type. The name provides a reference to the property in scripts or macros. The type defines the kind of values which can be assigned to the property.  Some properties have a pre-defined set of values they can be set to. For instance, the PictureSize property of the form object can only be set to one of four pre-defined options (PicSizeClip, PicSizeStretch, PicSizeTile or PicSizeZoom). Other properties are boolean, meaning that they can only be set to True or False. An example of this is the Visible property. There are other properties which require the user to enter a value, this might be a string value, as is the case for the Caption property, or some other value such as a file.

A property can be read and written (unless it's a read-only property) by scripts and macros. To reference an object's property, type the object's full path and name, followed by the dot (.) character, then the property name. For example, if you wanted to set the Visible property of a control named "InvoiceNumber" to false in a script you would use:

App.ActiveForm.InvoiceNumber.Visible = False

Newlook updates properties dynamically if something changes in the object at run-time. Properties for forms and controls can also be edited and viewed in the Designer (click the Forms button on the menu).

Events

In order to respond to events happening to objects at run-time, objects need a way of telling the outside world that something has happened. This is done through events. For example, when a CommandButton is clicked, the CommandButton object triggers a Click event. Most events in the Newlook object model have corresponding properties which allow the user to interact with the event. In the scenario above the OnClick property allows us to perform some action when the Click event of the CommandButton is triggered.

To run a macro or script when an event is triggered, you must assign the macro or script to the corresponding property of the object. This can be done in the property sheet in Designer, or programmatically, by using the dot notation described in the properties section above. When an event occurs, the object triggers the event and calls your script or macro (if any) assigned to the relevant property to handle the event.

Methods

Objects can also have methods. A method performs some specific functionality on the object. Some methods return a value. Just like properties and events, methods are specific to that object and only operate on that object alone. To call a method, type the object's full path followed by the dot (.) character, then the method name and any relevant parameters. For example, if you wanted to add a custom function key to your form at runtime, you would call the Add method of the function keys collection in a JScript code like this:

App.ActiveForm.FunctionKeys.Add("fncPrompt", "Prompt", nlKeyF4);

Many methods have optional parameters which may be omitted, in which case the default argument values will be used instead. Refer to individual method topics for information on the default values of method parameters.

See Also

Writing and Debugging Macros | Debugging scripts


© 2004-2021 looksoftware. All rights reserved.