Using COM/ActiveX in Lianja on Windows

From Lianjapedia
Jump to: navigation, search

Using COM/ActiveX with Lianja on Windows is quite straightforward.

You just use the CREATEOBJECT() built-in function in any of the supported scripting languages to create an object, and then use the ADDOBJECT() method on a Container to add COM/ActiveX components into your Apps.

COM/ActiveX is Windows specific so Apps that use this functionality will not run on Linux or Mac OS X

As with Visual FoxPro, you use the EVENTHANDLER() built-in function to connect the events emitted from the ActiveX control to a custom class which consumes these events in known methods corresponding to the names of the events that the particular ActiveX emits. This can be written in any of the supported scripting languages; Lianja/Visual FoxPro, Python, PHP or JavaScript.

Here is a simple example that embeds Internet Explorer into a "Form".

COM/ActiveX example

Example code

The code below will embed Internet Explorer into a Form. You can embed COM/ActiveX controls in any of the containers in the Lianja App Framework e.g. Form, Container, Control, or Page (Tab Page).

myform = createobject("form")
myform.resize(800, 600)
myform.addobject("ax", "{8856F961-340A-11D0-A96B-00C04FD705A2}")
ax.anchor = 15

Creating the COM/ActiveX component

You can specify the ActiveX control in several different formats.

The most efficient way is by using the registered component's UUID, e.g.


The second fastest way is to use the registered control's class name (with or without version number), e.g.


The slowest, but easiest way to use is to use the control's full name, e.g.

createObject("Calendar Control 9.0")

It is also possible to initialize the object from a file, e.g.


If the component's UUID is used the following patterns can be used to initialize the control on a remote machine, to initialize a licensed control or to connect to a running object:

To initialize the control on a different machine use the following pattern:


To initialize a licensed control use the following pattern:


To connect to an already running object use the following pattern:


The first two patterns can be combined, e.g. to initialize a licensed control on a remote machine:


Binding to events

Binding to events that are emitted from a COM/ActiveX component is simple. See below.

define class myeventhandler
    // handle the events you are interested in
    proc DownloadBegin()

    proc DownloadComplete()

    proc ProgressChange(currentvalue, maxvalue)

    // The "Special" HandleEvent method can be used to trace events but be sure to remove it in production systems 
    // as it incurs unnecessary performance overhead
    proc HandleEvent(name, arglist)

ie = createObject("{8856F961-340A-11D0-A96B-00C04FD705A2}")
myhandler = createObject("myeventhandler")
eventHandler(ie, myhandler)

Notice how there is no need to use any special "implements" command as in VFP as Lianja will introspect the ActiveX component for you. Events that you do not have methods for are just ignored.

The "special" HandleEvent method can be used to catch all events. You determine what the name of the event is by looking at the name parameter.