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:
01 ctrls type System.Windows.Forms.Control occurs any.
01 client-name pic x(30).
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.
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.
What you suggest here breaks all rules of encapsulation as those form control fields are marked as private for a reason.
You could create properties or public methods in C# for each of the textbox controls so that you can return the value of these fields when the method is called.
You could then create an interface definition in a separate project that defines each of these properties or methods and you could pass the current form to the COBOL class as a parameter of the interface type so that its methods could be called. You would add references to the interface project in both the C# and COBOL classes.
What I would really suggest is that you create a separate data only class containing properties that you could instantiate and populate in c# and then pass this class to COBOL as a parameter.
This just seems like a much simpler and cleaner approach.
If you require examples of either of these methods, let me know and I will provide them to you.
Yes, please give me an example of using the data only class.