Using an ActiveX Control

You use ActiveX controls in your application in the same way as you use native Visual LANSA controls.

This example shows how to use the Microsoft Web Browser ActiveX control which is installed on your PC if you have Microsoft Internet Explorer.

To try out the Microsoft web browser control, create a form. In the editor open the ActiveX Controls in Resources node of the Repository tab. Locate, select and then drag and drop the VA_WEBCTL control on your form (as always, you need to have the Design tab topmost to drag and drop a control).

Now you have a form with a ready-to-use web browser on it.

Display the Source tab of your form. As you can see a DEFINE_COM definition has been added for the web browser control:


The methods and events and the Visual LANSA properties of the control are now accessible in the Details tab.

From the Features window (F2) you can display a brief description of all the properties, events and methods of the control.

Note that the control has a Navigate method which displays a URL:

Add this statement to the initialize event of your form:

invoke method(#VA_WEBCTL.navigate) url(


To see how the browser control works, compile the form and execute it. The LANSA home page is displayed in the browser.

Setting Properties at Design Time

You use the properties of an ActiveX control in exactly the same way as you use the properties of a native LANSA control.

Note that with the web browser control we are using, some of the properties listed do not have any effect on the browser. This is because they are Internet Explorer properties only. For example, the AddressBar property has no effect in the web browser because, by definition, it does not have an address bar.

Set the width of the browser control by using its Width or Width_COM property (they are identical):

Retrieving the URL from the Browser Control

This section shows you how you can retrieve the value of a property from the browser control.

The browser control has a property LocationURL which retrieves the URL of the resource that the browser is currently displaying:

To use this property, add a push button and field to your form to retrieve the URL:

Set the properties of the button and the field:

Push button control   

caption('Get URL')


caption('URL:') labeltype(Caption) marginleft(50)

In the Click event of the push button, add this code to retrieve the URL:


change field(#std_texts ) to(#VA_WEBCTL.LocationURL)


Compile and execute the form. When the LANSA page is displayed in the browser control click on the Get URL button to see the URL:


This section shows how to use the events of an ActiveX control.

To see which events are available for the browser control display its Features (F2) and expand the list of its events.

The browser control has a DocumentComplete event which is triggered when the page has been found and downloaded. You can use this event to show a message when the page download is complete. Add this code to your form:


use builtin(MESSAGE_BOX_SHOW) with_args(OK OK Information 'Page Ready' 'The web page has been downloaded.')


Compile and execute the form. The completion message is displayed when the LANSA page has been downloaded:

A Note about Initializing ActiveX Controls

Note that visual ActiveX controls are not fully realized when the Visual LANSA CreateInstance Event is signalled. Non-visual components do not cause a problem.

This means that accessing any feature of a Visual ActiveX control in a CreateInstance event routine may cause runtime errors.  Use Initialize instead.