Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Once created, the .NET Component can be used the same way as any other Visual LANSA component. An instance of the component can be created and its properties, methods and events can be used. Some components are very simple and little programming is required to use them, others provide complex functionality and may require much more coding than using native Visual LANSA controls.

Define an instance of a component

Use the DEFINE_COM command. If the class does not have a constructor or has a constructor which takes no parameters then you may define the instance as either static or dynamic. Otherwise you must define the instance as dynamic:

     Define_Com Class

...

(#DOTNET1.TestClasses.MyClass)

...

 Name(#MyClass)

...

 Reference(*DYNAMIC)

...

If

...

the

...

class

...

is

...

a

...

control,

...

be

...

sure

...

to

...

parent

...

the

...

control

...

to

...

the

...

form

...

so

...

that

...

it

...

is

...

visible

...

on

...

the

...

form.

...

You

...

may

...

then

...

resize

...

and

...

move

...

the

...

control

...

in

...

Design

...

view:

...

     Define_

...

Com Class(#DOTNET1.DotNetControls.WebBrowserX)

...

 Name(#Browser)

...

 Displayposition(4)

...

 Parent(#COM_OWNER)

...

 Tabposition(4)

...

Instantiating

...

a

...

dynamic

...

instance

...

If

...

the

...

component

...

instance

...

has

...

been

...

defined

...

as

...

dynamic,

...

the

...

instance

...

will

...

need

...

to

...

be

...

instantiated

...

with

...

either

...

the

...

*New

...

or

...

SET_REF

...

commands.

...

Either

...

command

...

allows

...

you

...

to

...

specify

...

a

...

constructor.

...

How

...

to

...

define

...

classes

...

with

...

static

...

methods

...

To

...

use

...

static

...

methods

...

in

...

a

...

class

...

you

...

must

...

define

...

a

...

component

...

instance.

...

The

...

instance

...

may

...

be

...

defined

...

as

...

static

...

or

...

dynamic.

...

Once

...

defined,

...

static

...

methods

...

from

...

the

...

class

...

may

...

be

...

called

...

at

...

any

...

time.

...

If

...

a

...

dynamic

...

component

...

instance

...

has

...

been

...

defined,

...

static

...

methods

...

may

...

be

...

called

...

without

...

instantiating

...

the

...

instance.

...

This

...

allows

...

the

...

use

...

of

...

static

...

classes

...

and

...

also

...

allows

...

the

...

instantiation

...

of

...

classes

...

with

...

private

...

or

...

protected

...

constructors

...

(assuming

...

the

...

class

...

has

...

static

...

methods

...

to

...

instantiate

...

itself).

...

*NEW

...

If

...

the

...

class

...

does

...

not

...

have

...

a

...

constructor

...

or

...

has

...

a

...

constructor

...

that

...

takes

...

no

...

parameters,

...

then

...

you

...

may

...

specify

...

no

...

constructor

...

or

...

a

...

constructor

...

with

...

no

...

parameters.

...

Otherwise

...

the

...

parameters

...

should

...

be

...

passed

...

similar

...

to

...

a

...

method

...

call.

Panel
bgColor#ffffcc

Variable <= *New

Variable <= *New 

---

 Fully qualified class name 

Fully qualified class name ------------------

 > >

>
>---------------------------------------------------------------------

 >   |                                                             |   -- .Constructor Name 

>
   |                                                                                                 |
    --.Constructor Name -------------------------------------------

                        |                                      |                         -- ( 


                                       |                                                          |
                                       -- ( --------------------------------

 

)

 -–                               |                         |                                

-–
                                               |                                         |
                                                --------

 Parameter 

Parameter --------

                                 |                   |                                   


                                                    |                                |
                                                     ----------<----------

 

SET_REF

...

For

...

information,

...

refer

...

to

...

the SET_REF in the Technical Reference Guide.

Example

     C#
   public ConstructorTests() {…}
   public ConstructorTests( int aNumber ) {…}
   public ConstructorTests( int aNumber, ref DateTime aDateTime, String aString ) {…}

  RDML
   Define_Com Class(#DOTNET1.TestClasses.ConstructorTests)

...

 Name(#LCom01)

...

 Reference(*DYNAMIC)

...



   Define Field(#LNum01)

...

 Type(*INT)

...

 Length(4)

...


   Define Field(#LStr01)

...

 Type(*CHAR)

...

 Length(50)

...


   Define Field(#LDTime01)

...

 Type(*DATETIME)

...

 Length(26)

...



      #LCom01 <= *New #DOTNET1.TestClasses.ConstructorTests

...


   Set_

...

Ref Com(#LCom01)

...

 To(*CREATE_

...

AS #DOTNET1.TestClasses.ConstructorTests)

...



     #LCom01 <= *New #DOTNET1.TestClasses.ConstructorTests.ConstructorTests()

...


   Set_

...

Ref Com(#LCom01)

...

 To(*CREATE_

...

AS #DOTNET1.TestClasses.ConstructorTests.ConstructorTests)

...



     #LCom01 <= *New #DOTNET1.TestClasses.ConstructorTests.ConstructorTests#2(

...

 #LNum01 #LDTime01 #LStr01 )
   Set_Ref Com(#LCom01)

...

 To(*CREATE_

...

AS #DOTNET1. TestClasses.ConstructorTests.ConstructorTests#2)

...

 Anumber(#LNum0501)

...

 Adatetime(#LDTi0501)

...

 Astring(#LStr0501)

...

Using

...

properties

...

and

...

variables

Syntax

Panel
bgColor#ffffcc

RDML Variable . .NET Property Name

Syntax RDML Variable . .NET Property Name

-----------------------------------------------

 >                                     |                                           |                                      -- \[ 

>
                                                             |                                                               |
                                                             -- \[ ---------------------------------

 

\]

 -–                                            |                             |                                           

-–
                                                                      |                                           |
                                                                       -----------

 Index 

Index -----------

                                              |                       |                                               


                                                                           |                                  |
                                                                            -----------<-----------

  RDML Variable . .NET Variable Name   Example C#    public int Counter    \{       get \{ return mCount; \}       set \{ mCount = value; \}    \}   RDML    Define_Com Class


RDML Variable . .NET Variable Name  

Example

     C#
   public int Counter   
{
      get { return mCount; }
      set { mCount = value; }
  }

  RDML
   Define_Com Class(#DOTNET1.TestClasses.MyClass)

...

 Name(#NumericClass)

...



     #NumericClass.

...

Counter :=

...

 120

     #STD_

...

INT :=

...

 #NumericClass.Counter

...



     Begin_

...

Loop Using(#STD_INT)

...

 To(#NumericClass.Counter)

...

 Step(2)

...


   …
   End_Loop

...

Calling

...

Methods

Syntax

Panel
bgColor#ffffcc

RDML Variable . Method Name

Syntax RDML Variable . Method Name 

-----------------------------------------------

 >                              |                                           |                               -- ( 

>
                                                   |                                                              |
                                                    -- ( ---------------------------------

 

)

 -–                                     |                             |                                      

-–
                                                           |                                           |
                                                           --------

 Parameter 

Parameter ----------

                                       |                       |                                         


                                                              |                                    |
                                                                -----------<-----------

Example C#    public void       IncrementDateByDays(          ref DateTime                           dateTime,          int                                    dayAdjustment )    \{       dateTime = dateTime.AddDays( dayAdjustment );    \}   RDML    Define_Com Class

Example

     C#
   public void
      IncrementDateByDays(
         ref DateTime                           dateTime,
         int                                    dayAdjustment )
  {
      dateTime = dateTime.AddDays( dayAdjustment );
  }
  RDML
   Define_Com Class(#DOTNET1.TestClasses.MyClass)

...

 Name(#LClass01)

...


   Define Field(#LDat01)

...

 Type(*DATETIME)

...


   Define Field(#LDat02)

...

 Type(*DATETIME)

...



      #LDat01 :=

...

 '1954-04-

...

25 10:04:00.000000'

...


   #LDat02 :=

...

 '1954-05-

...

05 10:04:00.000000'

...



     #LClass01.IncrementDateByDays(

...

 #LDat01 10 )

     If ((#LDat01 = #LDat02))

   Endif


    C#
   public String
      DoubleIntegerReturnString(
         int                                    number,
         out int                                result )
  {
      result = number * 2;
      return String.Format( "Double {0} is {1}", number, result );
  }

  RDML
   Define_Com Class(#DOTNET1.TestClasses.MyClass)

...

 Name(#LClass01)

...


   Define Field(#LNum01)

...

 Type(*INT)

...

 Length(4)

...


   Define Field(#LNum02)

...

 Type(*INT)

...

 Length(4)

...


   Define Field(#LStr01)

...

 Type(*CHAR)

...

 Length(80)

     #LNum01 := 411
   #LStr01 := #LClass4101.DoubleIntegerReturnString( #LNum01 #LNum02 )
   If (#LNum02 = (#LNum01 * 2))
   …
   Endif

Event Handling

Event handling functions are defined using the EVTROUTINE command. See the EVTROUTINE documentation in the Technical Reference Guide for further details about this command. The basic syntax of the command is as follows:

Panel
bgColor#ffffcc

EVTROUTINE --- HANDLING ( Variable Name . Event Name

     #LNum01 := 411    #LStr01 := #LClass4101.DoubleIntegerReturnString( #LNum01 #LNum02 )    If (#LNum02 = (#LNum01 * 2))    …    Endif   Event Handling Event handling functions are defined using the EVTROUTINE command. See the [<span style="color: #0000ee"><span style="text-decoration: underline; ">EVTROUTINE</span></span>|../../../lansa015/Content/lansa/evtroutine.htm] documentation in the Technical Reference Guide for further details about this command. The basic syntax of the command is as follows: EVTROUTINE --- HANDLING ( Variable Name . Event Name 

)------------

 > >

>
>----------------------------------------------------------------------------

 >                  |                                              |                   

>
                               |                                                                             |
                                 ----

 Parameter Name

Parameter Name(

 Variable Name 

Variable Name )

 

----

 

)

 

-–

                   |                                     |                     


                                    |                                                            |
                                      ---------------------<-----------------

Example C#    public class EventArgs1    \{       private String         mName;         public EventArgs1() \{   \}         public String Name       \{          get \{ return mName; \}          set \{ mName = value; \}       \}    \}      Public class EventTests    \{       public event MyEventDelegate MyEvent;       public delegate void MyEventDelegate( String str, EventArgs1 eventArgs );    \}   RDML    Define_Com Class

Example

     C#
   public class EventArgs1   
{
      private String         mName;

        public EventArgs1() {   }

        public String Name

      {
         get { return mName; }
         set \{ mName = value; }
     }
  }

     Public class EventTests
  {
      public event MyEventDelegate MyEvent;
      public delegate void MyEventDelegate( String str, EventArgs1 eventArgs );
  }

  RDML
   Define_Com Class(#DOTNET1.TestClasses.EventTests)

...

 Name(#EventTest)

...



     Evtroutine Handling(#EventTest.MyEvent)

...

 Str(#s1)

...

 EventArgs(#c1)

...


      #STD_

...

TEXT :=

...

 #s1
      #STD_NAME := #c1.Name
   Endroutine