Accessing properties of controls on a C# form from a managed COBOL program

My solution has a C# project and a COBOL project.  Several text boxes are entered on a C# form which then calls a COBOL program to do the validation.  The C# project has a reference to the COBOL project so that it can create an instance of the COBOL program before calling it.  There are several ways I can pass the text box values to the COBOL program.

1. Pass them in linkage, including use of smart linkage (can use smart linkage if the COBOL program is not a class).

2. Declaring properties in the COBOL program and setting them from the C# program before calling it.

3. Passing the Windows form object to the COBOL program and using its Controls collection to get the Text properties of each text box I need to   validate. 

The code for the last method looks like this:

 method-id ValidateMethod.
       local-storage section.
    
       01 ctrls type System.Windows.Forms.Control occurs any.

       01 client-name pic x(30).
       
       linkage section.
       01 oform type System.Windows.Forms.Form.
       procedure division using oform.
   
           SET ctrls to  oform::Controls::Find("tbClientName", true)
           if ctrls::Count = 1
               set client-name to ctrls(1)::Text.
         
          
           goback
       end method.

An advantage to using the third method is I don't have to add properties to my COBOL program or pass a group of fields in linkage.  I can also set the Text property of a text box from COBOL if I need to update it.  I can't add a reference in my COBOL project to the C# project because that would be a circular dependency and it's not allowed, so I can't add property declarations to my C# class which I would be able to get from COBOL.

My question is, is this third method even legit ?  The controls of a form are private to the form class which encapsulates data and methods so we would normally get values from form controls via public properties.  But when your form has twenty or more controls this method gets around the hassle of having to pass a large number of fields to the COBOL program or add a large number of get/set property statements to it.

Tags:

Parents Reply Children
No Data