Versions Compared

Key

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

Wiki MarkupThe .NET Component can be used the same way as any other Visual LANSA component.

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. Variable <Variable <=   *New New ---  Fully qualified class name Fully qualified class name ------------------  > > >-----------------------------------------------------------------  > >   |                                                             |   --   .Constructor Name Constructor Name ------------------------------------------                         |                                      |                         --   (   -----------------------------   )   -–                               |                         |                                -------  Parameter Parameter -------                                  |                   |                                   ---------<---------   SET_REF For information, refer to the [<span style="color: #0000ee"><span style="text-decoration: underline; ">SET_REF</span></span>|../../../lansa015/Content/lansa/set_ref.htm] in the Technical Reference Guide. Example C#    public ConstructorTests   public ConstructorTests()   \{…\}    public ConstructorTests( int aNumber )    public ConstructorTests( int aNumber ) \{…\}    public ConstructorTests( int aNumber, ref DateTime aDateTime, String aString )    public ConstructorTests( int aNumber, ref DateTime aDateTime, String aString ) \{…\}   RDML    Define_Com ClassCom Class(#DOTNET1.TestClasses.ConstructorTests)  NameName(#LCom01)  ReferenceReference(*DYNAMIC)      Define Field   Define Field(#LNum01)  TypeType(*INT)  LengthLength(4)    Define Field   Define Field(#LStr01)  TypeType(*CHAR)  LengthLength(50)    Define Field   Define Field(#LDTime01)  TypeType(*DATETIME)  LengthLength(26)      #LCom01 <   #LCom01 <=   *New #DOTNET1New #DOTNET1.TestClasses.ConstructorTests    Set_Ref ComRef Com(#LCom01)  ToTo(*CREATE_AS #DOTNET1AS #DOTNET1.TestClasses.ConstructorTests)      #LCom01 <   #LCom01 <=   *New #DOTNET1New #DOTNET1.TestClasses.ConstructorTests.ConstructorTests()    Set_Ref ComRef Com(#LCom01)  ToTo(*CREATE_AS #DOTNET1AS #DOTNET1.TestClasses.ConstructorTests.ConstructorTests)      #LCom01 <   #LCom01 <=   *New #DOTNET1New #DOTNET1.TestClasses.ConstructorTests.ConstructorTests#2(  #LNum01 #LDTime01 #LStr01 #LNum01 #LDTime01 #LStr01 )    Set_Ref ComRef Com(#LCom01)  ToTo(*CREATE_AS #DOTNET1AS #DOTNET1.  TestClassesTestClasses.ConstructorTests.ConstructorTests#2)  AnumberAnumber(#LNum0501)  AdatetimeAdatetime(#LDTi0501)  AstringAstring(#LStr0501) Using properties and variables Syntax RDML Variable RDML Variable .   .NET Property Name NET Property Name -----------------------------------------------  > >                                     |                                           |                                      --   \[   ---------------------------------   \]   -–                                            |                             |                                             -----------  Index Index -----------                                               |                       |                                                -----------<-----------   RDML Variable RDML Variable .   .NET Variable Name NET Variable Name   Example C#    public int Counter C#    public int Counter    \{       get       get \{  return mCountreturn mCount;   \}       set       set \{  mCount mCount =  valuevalue;   \}    \}   RDML    Define_Com ClassCom Class(#DOTNET1.TestClasses.MyClass)  NameName(#NumericClass)      #NumericClass.Counter Counter :=  120 120      #STD_INT INT :=  #NumericClass#NumericClass.Counter      Begin_Loop UsingLoop Using(#STD_INT)  ToTo(#NumericClass.Counter)  StepStep(2)    …    End_Loop   Calling Methods Syntax RDML Variable . Method Name RDML Variable . Method Name -----------------------------------------------  > >                              |                                           |                               --   (   ---------------------------------   )   -–                                     |                             |                                      --------  Parameter Parameter ----------                                        |                       |                                         -----------<----------- Example C#    public void    public void       IncrementDateByDays(          ref DateTime                           dateTime,          int                                    dayAdjustment )          ref DateTime                           dateTime,          int                                    dayAdjustment )    \{       dateTime       dateTime =  dateTimedateTime.AddDays(  dayAdjustment dayAdjustment );    \}   RDML    Define_Com ClassCom Class(#DOTNET1.TestClasses.MyClass)  NameName(#LClass01)    Define Field   Define Field(#LDat01)  TypeType(*DATETIME)    Define Field   Define Field(#LDat02)  TypeType(*DATETIME)      #LDat01    #LDat01 :=   '1954-04-25 1025 10:04:00.000000'    #LDat02    #LDat02 :=   '1954-05-05 1005 10:04:00.000000'      #LClass01.IncrementDateByDays(  #LDat01 10 #LDat01 10 )      If    If ((#LDat01 #LDat01 =  #LDat02#LDat02))    Endif     C#    public String     public String        DoubleIntegerReturnString(          int                                    number,          out int                                result          out int                                result )    \{       result       result =  number number *  22;       return String      return String.Format(   "Double Double \{0\}  is is \{1\}",  numbernumber,  result result );    \}   RDML    Define_Com ClassCom Class(#DOTNET1.TestClasses.MyClass)  NameName(#LClass01)    Define Field   Define Field(#LNum01)  TypeType(*INT)  LengthLength(4)    Define Field   Define Field(#LNum02)  TypeType(*INT)  LengthLength(4)    Define Field   Define Field(#LStr01)  TypeType(*CHAR)  LengthLength(80)      #LNum01    #LNum01 :=  411    #LStr01 411    #LStr01 :=  #LClass4101#LClass4101.DoubleIntegerReturnString(  #LNum01 #LNum02 #LNum01 #LNum02 )    If    If (#LNum02 #LNum02 =   (#LNum01 #LNum01 *  22))    …    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 EVTROUTINE ---  HANDLING HANDLING (  Variable Name Variable Name .  Event Name Event Name )------------  > > >-----------------------------------------------------------------  > >                  |                                              |                   ----  Parameter NameParameter Name(  Variable Name Variable Name )   ----   )   -–                    |                                     |                     --------------------<---------------- Example C#    public class EventArgs1 C#    public class EventArgs1    \{       private String         mName      private String         mName;         public EventArgs1      public EventArgs1()   \{   \}         public String Name         public String Name       \{          get          get \{  return mNamereturn mName;   \}          set          set \{  mName mName =  valuevalue;   \}       \}    \}      Public class EventTests      Public class EventTests    \{       public event MyEventDelegate MyEvent;       public delegate void MyEventDelegate( String str, EventArgs1 eventArgs );       public event MyEventDelegate MyEvent;       public delegate void MyEventDelegate( String str, EventArgs1 eventArgs );    \}   RDML    Define_Com ClassCom Class(#DOTNET1.TestClasses.EventTests)  NameName(#EventTest)      Evtroutine Handling   Evtroutine Handling(#EventTest.MyEvent)  StrStr(#s1)  EventArgsEventArgs(#c1)       #STD_TEXT TEXT :=  #s1 #s1       #STD_NAME NAME :=  #c1#c1.Name    Endroutine [<span style="color: #0000ee"><span style="text-decoration: underline; ">&amp;&lt;img src="../resources/images/opentoc-dark.png" title="Open Contents List" border="0"&amp;&gt;</span></span>|../../index.htm#lansa/l4wdev07_0390.htm]