Highlighted
Absent Member.
Absent Member.
1655 views

Visual Cobol Managed & interfaces

Jump to solution

[Migrated content. Thread originally posted on 01 December 2011]

Hello,

I need to implement a little class inside a form, and should implement the interface 'ICompare':

class ListViewItemComparer : IComparer

I do not know how to code this in Visual COBOL, sorry.

Regards
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol Managed & interfaces

Jump to solution
Something like this might work:


      $set ilusing"System.Collections"
       class-id MngListView.ListViewItemComparer implements type IComparer.

       working-storage section.
       01 mycolumn binary-long.
       method-id New.
       local-storage section.
       procedure division.
           set mycolumn to 0
           goback.
       end method.

       method-id New.
       local-storage section.
       procedure division using lnkcolumn as binary-long.
           set mycolumn to lnkcolumn
           goback.
       end method.

       method-id Compare.
       local-storage section.
       01 lsx   type ListViewItem.
       01 lsy   type ListViewItem.
       procedure division using by value #x as object #y as object returning return-item as binary-long.
          set lsx to #x as type ListViewItem
          set lsy to #y as type ListViewItem
          set return-item to type String::Compare(lsx::SubItems::Item(mycolumn)::Text, lsy::SubItems::Item(mycolumn)::Text)
       end method.
     






View solution in original post

0 Likes
6 Replies
Highlighted
Absent Member.
Absent Member.

RE: Visual Cobol Managed & interfaces

Jump to solution
The syntax for interfaces in managed COBOL is "implements type". So, your example should look like this:

class-id ListViewItemComparer public implements type IComparer
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Visual Cobol Managed & interfaces

Jump to solution
Thank you.

Now I am trying to translate the last of these methos:
    // Implements the manual sorting of items by columns.
    class ListViewItemComparer : IComparer
    {
        private int col;
        public ListViewItemComparer()
        {
            col = 0;
        }
        public ListViewItemComparer(int column)
        {
            col = column;
        }
        public int Compare(object x, object y)
        {
            return String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
        }
    }

I find it extremely tricky. Arrived at this point, I do not know how to continue:
      $set ilusing"System.Collections"
       class-id MngListView.ListViewItemComparer public implements type IComparer.

       
       working-storage section.
       01  myColumn             pic 9.

       method-id InstanceMethod.
       local-storage section.
       procedure division.

           goback.           
       end method.
       
       method-id ListViewItemComparer final public.
       procedure division.
           set myColumn to 0.
       end method.
       

       method-id ListViewItemComparer final public.
       linkage section.
       01 newColumn         pic 9.
       procedure division using by value newColumn.
           set myColumn to newColumn.
       end method.

       method-id Compare final public.
       working-storage section.
       01 resultCompare    type Int32.
       01 string1          type String.
       01 string2          type String.
       01 item1            type ListViewItem.
       01 item2            type ListViewItem.
       linkage section.
       01 x                type Object.
       01 y                type Object.
       01 result           type Int32.
       procedure division using by value x, y returning result.
           set item1 to x as type ListViewItem.
           set item2 to y as type ListViewItem.
           *>set string1 to item1::SubItems(myColumn) as String.
           
           *>return String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
           set result to resultCompare.
       end method.
       
       end class.

Could you give me a hand on this subject? I am afraid I am stuck.

Thank you.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Visual Cobol Managed & interfaces

Jump to solution
The problem you are having is in your ListViewItemComparer. The interface defines the parameter and return values to be of type int. the COBOL equivalent of this would be binary-long but you are using pic 9 which is incompatible.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol Managed & interfaces

Jump to solution
Something like this might work:


      $set ilusing"System.Collections"
       class-id MngListView.ListViewItemComparer implements type IComparer.

       working-storage section.
       01 mycolumn binary-long.
       method-id New.
       local-storage section.
       procedure division.
           set mycolumn to 0
           goback.
       end method.

       method-id New.
       local-storage section.
       procedure division using lnkcolumn as binary-long.
           set mycolumn to lnkcolumn
           goback.
       end method.

       method-id Compare.
       local-storage section.
       01 lsx   type ListViewItem.
       01 lsy   type ListViewItem.
       procedure division using by value #x as object #y as object returning return-item as binary-long.
          set lsx to #x as type ListViewItem
          set lsy to #y as type ListViewItem
          set return-item to type String::Compare(lsx::SubItems::Item(mycolumn)::Text, lsy::SubItems::Item(mycolumn)::Text)
       end method.
     






View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Visual Cobol Managed & interfaces

Jump to solution
Hello Chris,

Thanks a lot for your help! I was really at my wits end with that issue.

It worked out perfectly.

The adaptation to this new language is really hard, but it is also worth learning it.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol Managed & interfaces

Jump to solution
You are welcome.

We agree completely that the new syntax is well worth the effort of learning.

As with anything, the more you use it the easier it will become 🙂
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.