ActiveX Example 1 - Show a Form

This example shows the essentials of how to expose properties, events and methods of an ActiveX LANSA form:

Source that makes up this example:  

Name

Type

Description

AXFORMA

Visual LANSA Component

Visual LANSA Source

Project1

Visual Basic Project

Project Definition

Form1

Visual Basic Form

Visual Basic - Code

Session.cfg

Configuration file

Session Configuration (Session.cfg)

 

Refer to Show a Form for the source code.

Step 1. Add the Visual LANSA Component

In this step you create an ActiveX LANSA form to display employee details:

To create the ActiveX component:

1.  Open the LANSA editor and create a new component named AXFORMA, type Form.

2.  Copy and paste the source code from Case 1 - Visual LANSA Source into the form.

3.  Select the Set ActiveX Attributes command in the ribbon. (The sample code you have copied already has these attributes, but setting them again does not do any harm.)

     This step exposes the Visual LANSA component as an ActiveX Control. You can see what thecommand does by first deleting the existing four ActiveX attribute statements (Attribute Class(#PRIM_ATTR.AX_) from the source before selecting the menu option)

4.  Compile the form.

Step 2. Add the Visual Basic Form

In this step you create a Visual Basic form which uses the LANSA ActiveX form:

To create this form:

1.  Close Visual Basic.

2.  Start Notepad, open the form (Form<n>.frm) created in the General Setup Tasks.

3.  Replace the code in Notepad with the source code from Case 1 - Visual Basic - Object, then Save.

4.  Start Visual Basic and open the Project (Project<n>.vbp) created in the General Setup Tasks.

5.  Open the form (Form<n>.frm)

6.  Copy  the source code from Case 1 - Visual Basic - Code to the form's code, then Save.

7.  Right-click in the Visual Basic toolbox and select components from the popup menu. 

8.  Scroll down and check LANSA.AXFORMA.  This will add a LANSA icon to the toolbox.

10. Click on the  AXFORMA icon to select it and on the form drag out a rectangle and release the left mouse key. The LANSA ActiveX form has now been added to the Visual Basic form:

11. Display the properties of the form and change its name from AXFORMA1 to AXFORMA.

     Notes:

12. In the Visual Basic LOAD routine (Private Sub Form_Load) modify the login script to your requirements. For example:

      Call ConnectToLansa("user1", "mypassword", "c:\ActiveXTests\session.cfg")

13. Save, then compile the Visual Basic Project using the Make Project<n>.exe option in the File menu.

     You can now view the sample Personnel data by executing the program and typing in an Employee Number, then clicking on Show.