Procedure Parameter *Group Type - Passed an Array Element of the Group Type

Hi !

Please tell me what could be the error when passing an array element to the procedure ?

  Map
    MyProc(*TypeMyGroup MyGroup)
  end
  
TypeMyGroup Group,Type
Field1        Byte
  end

MyGroup  Group(TypeMyGroup).
MyDim    Group(TypeMyGroup),Dim(3).
  
  Code  
  MyProc(MyDim[1])    ! Compile: No matching prototype available :(
  
  MyGroup = MyDim[1]  ! OK
  MyProc(MyGroup)

Is it possible that the array was declared incorrectly? Thanks ! :slight_smile:

Hi @Genricke

There maybe other ways folks here come up with. This works how you would expect though. It does mean a slight change of syntax.

          PROGRAM
          Map
            MyProc(long pGroup)
          end
  
TypeMyGroup   Group,Type
Field1          Byte
              end

MyGroup   Group(TypeMyGroup).
MyDim     Group(TypeMyGroup),Dim(3).
  
  Code  
  MyDim[1].Field1 = 32
  MyProc(ADDRESS(MyDim[1]))
  
  MyGroup = MyDim[1]  
  MyProc(ADDRESS(MyGroup))
    
MyProc    PROCEDURE(long pGroup)
MyProcGroup &TypeMyGroup
  CODE
  MyProcGroup &= (pGroup)  !Bracket important here
  MESSAGE('Group field value: ' & MyProcGroup.Field1)

Regards

Mark

1 Like

Thank you. It turns out that MyGroup and MyDim[1] have different data types… :frowning:

Another way is a Reference assignment of a single to the Array i.e. MyGroupRef &= MyDim[1]. That way the Procedure can remain typed to take a MYGroupType, and the pass by address works so changes in the procedure change the MyDim[1].

I would say more typical Clarion code would be a Queue of these Groups.

  PROGRAM
  Map
    TestPassArrayOfTypedGroup()
    MyProc(*TypeMyGroup MyGroup)
  end
  
TypeMyGroup Group,Type
Field1        Byte
            End
    CODE
    TestPassArrayOfTypedGroup()

TestPassArrayOfTypedGroup    PROCEDURE()    
MyGroup  Group(TypeMyGroup).
MyDim    Group(TypeMyGroup),Dim(3).
MyGroupRef  &TypeMyGroup
  Code 
!  MyProc(MyDim[1])    ! Compile: No matching prototype available 
  
  MyDim[1].Field1 = 2
  MyGroup = MyDim[1]  ! OK
  MyProc(MyGroup)         
  MyDim[1] = MyGroup  !Carl--> Must set Array [1] = passed *MyGROUP

  !Carl--> New code to pass Reference &= Array [1]
  MyGroupRef &= MyDim[1]  !Reference assign to pass (*MyGroup) changes MyDim[1]  
  MyDim[1].Field1 = 3
  MyProc(MyGroupRef)      !Really oass *MyDim[1] 
  Message('After Pass MyGroupRef  &= MyDim[1] '& |
         '|? Field1 = 30| MyDim[1].Field1 = '& MyDim[1].Field1 )
!---------------------------------------
MyProc  PROCEDURE(*TypeMyGroup MyGroup)  
    CODE
    Message('In MyProc Field1=' & MyGroup.Field1) 
    !Change to see pass * changes caller data
    MyGroup.Field1 *= 10
    RETURN

2 Likes

Thanks ! If there are no options with the “correct” array declaration, this solves the problem. :smiley: