The .NET bridging interface includes a graphical utility known as NETDEFGEN. This utility allows you to view and select .NET assemblies for translation to a COBOL COPY file. It is similar to the AXDEFGEN utility that ACUCOBOL-GT provides for programming with ActiveX and COM objects. However, NETDEFGEN is designed to work with .NET assemblies.
The COPY files generated by NETDEFGEN supply the ACUCOBOL-GT compiler with all the necessary information for interfacing with .NET assemblies. When you include the COPY files in your COBOL program, you can interact with the .NET assembly via these COBOL statements: DISPLAY, CREATE, MODIFY, INQUIRE, and DESTROY.
Invoke .NET assemblies from your ACUCOBOL-GT program as follows:
The utility automatically generates a COPY file for the chosen assembly. For information on the contents of NETDEFGEN COPY files, see the NETDEFGEN Utility Reference.
The utility also generates something known as an event DLL. The event DLL is named after the NameSpace class found in the COPY file, appended by the suffix ".dll".
SPECIAL-NAMES COPY "netcontrol1.def". COPY "netcontrol2.def". .
If the .NET control that you are adding is graphical, (i.e., it has the word "Visual" in the COPY file NameSpace class definition), you can add it to your program in one of two ways:
screen section.
01 screen-1.
03 SOME-NETCONTROL, "@My.Assembly",
LINE 1, COL 2,
NAMESPACE IS "My.Test.Namespace",
CLASS-NAME IS "MyGUIClass",
CONSTRUCTOR IS CONSTRUCTOR2(PARM1, PARM2, PARM3,
PARM4, PARM5, PARM6, PARM7),
EVENT PROCEDURE IS USERCONTROL-EVENTS.
DISPLAY "@My.Assembly"
NAMESPACE IS "My.Test.Namespace"
CLASS-NAME IS "MyGUIClass"
EVENT PROCEDURE IS MY-EVENT-PROCEDURE
HANDLE IS MY-GUI-HANDLE.
If the .NET assembly that you are adding is non-graphical, use the CREATE statement to add it to your program as shown below:
CREATE "@My.Assembly"
NAMESPACE IS "My.Test.Namespace"
CLASS-NAME IS "MyClass"
HANDLE IS MY-NONGUI-HANDLE.
Note that .NET properties, methods, and events should always be prepended with an "@" sign in case they clash with COBOL reserved words or ACUCOBOL-GT graphical control property and style names. The "@" character identifies the relationship of the name to .NET or ActiveX.
MODIFY MY-NONGUI-HANDLE printIteration = NUMBRPRINTS.
MODIFY MY-NONGUI-HANDLE lastName = LAST-NAME.
MODIFY MY-NONGUI-HANDLE "ToLog"("Hello From COBOL", 99, "It's a Good Thing").
If you want to retrieve a property value, you can use the INQUIRE statement. For example:
INQUIRE MY-NONGUI-HANDLE printIteration IN QPRINTS.
INQUIRE MY-NONGUI-HANDLE lastName IN LAST-NAME.
At run time, your COBOL program transparently starts the .NET CLR, loads the requisite .NET assemblies and event handlers, executes .NET assembly methods, and returns the results to the COBOL program.