# Why can't I New() a GROUP and what workaround/alternatives are there?

It seems strange to me that you cannot New() a GROUP in Clarion. I seem to recall that there is an actual reason for this but I cannot find a reference describing that reason and now I am curious.

Possible alternatives?

Using a QUEUE instead, but just using it for the structure:

``````myFakeGroup_Type     GROUP,TYPE
someField              LONG
END
myFakeGroup          &myFakeGroup_Type
CODE

myFakeGroup &= New(myFakeGroup_Type)

myFakeGroup.someField = 12
Stop(myFakeGroup.someField)
Dispose(myFakeGroup)
``````

Using a STRING + GROUP:

``````myGroup_Type         GROUP,TYPE
someField              LONG
END
myGroupString        &STRING
myGroup              &myGroup_Type
CODE

myGroupString &= New(STRING(Size(myGroup_Type)))

myGroup.someField = 12
Stop(myGroup.someField)
Dispose(myGroupString)
``````

Note: With that approach I think you need to be careful about the size if you have Dim() variables in your GROUP.

1 Like

You can use a CLASS as your GROUP
I believe it uses another 4 or 8 bytes, but for most use cases that doesn’t matter.

You could even declare the class as

``````MyGroupClass  CLASS(myFakeGroup_Type),TYPE
END
``````

One problem with using classes vs. groups
Is when you want to copy all values like this

``````GroupClassA  &MyGroupClass
GroupClassB  &MyGroupClass
CODE
GroupClassA &= NEW MyGroupClass
GroupClassB &= NEW MyGroupClass
GroupClassA.SomeField = 47

GroupClassB = GroupClassA  !<--- UNUSUAL TYPE CONVERSION
``````

above is a normal syntax (for real groups) to copy all fields
however for classes, this will generate a warning UNUSUAL TYPE CONVERSION

When I requested some sort of fix to the compiler
Alexey just suggested that I use a memcpy to avoid the warning