No need to be abusive when nice people are trying to help you out.
No ! Translation difficulties are possible ā¦
I am ready to read any answers, but I wanted to clarify my task.
For testing I would change CSTRING to PSTRING because the 1st byte contains the length so messages clearly show Length=32 indicating it contains a Space i.e. <20h> = CHR(32). The Length of a CSTRING is based on finding the first CHR(0) which is not going to exist in a Group cleared to all Spaces, so LEN() returns is ???
You have proven that Clear(gBarCode.overlay)
works. The Overlay GROUP has a DIM(3) so the Topic of āHow do I clear a GROUP with an Array?ā is not complete.
You have proven that Clear(gBarCode)
fails to clear an inner child GROUP with a DIM(). So adjusting topic to note somethng about āinside a Parent GROUPā.
Note this problem will also happen on CLEAR of a RECORD or QUEUE containing a GROUP with DIM().
The Clear(gBarCode)
works if there is no DIM() on Overlay. So the RTL properly handles clearing Group child fields ā¦ It fails that it treats Groups with DIM as a big STRING:
What will work for you is moving the DIM from the GROUP onto the Child fields:
What also would work is changing CSTRING to a normal Clarion STRING. But Clear() has trouble with all types e.g. DECIMAL would = -2020.20.
I understand your need to generate a Clear for any type of group.
You could create a custom data type and store the original values to restore them when necessary. This way, you avoid depending on specific types.
Regarding the use of the STACK to clear a structure recursively, I donāt find a clear justification. However, it could be useful in more complex scenarios, such as generating JSON or XML from data structures.
TPrintList group,type
Task group,Dim(3)
Flag long,Dim(3)
Print bool(false)
type cstring(21)
text cstring(129)
Doc group,Dim(3)
Page long,Dim(3,3)
end
end
end
...
PrintListCleared like(TPrintList) ! Clear Structure.
PrintList like(TPrintList) ! Working Structure.
...
Hello again Genricke
I have made changes to your EasyClear to use howmany() for arrays as mentioned in my earlier message above.
EasyClear Procedure(*Group MyGroup) !,long,proc
lCount Long
aFieldRef Any,Auto
pGroupRef &Group
dimCount long,auto
x long,auto
code
loop
lCount += 1
aFieldRef &= What(MyGroup, lCount)
if aFieldRef &= Null then break. ! End of Group
dimCount = howmany(MyGroup, lCount)
x = 1
if dimCount > 1 then aFieldRef &= What(MyGroup, lCount, 1).
loop
if IsGroup(MyGroup, lCount)
pGroupRef &= GetGroup(MyGroup, lCount, choose(dimCount > 1,x,0))
if x >= dimCount
lCount += easyClear(pGroupRef)
else
easyClear(pGroupRef)
end
else
clear(aFieldRef)
end
if x >= dimCount then break.
x += 1
aFieldRef &= What(MyGroup, lCount, x)
if aFieldRef &= Null then break. ! just in case - should NOT happen
end
end
return lCount - 1
OK well hopefully that works. If it doesnāt then please show an example where it fails and I will have a look at it - but as Jeff suggests, it is good to be polite and kind to those who are trying to help!
cheers again
Geoff R
Have a look at the c function āmemsetā & try something like ā¦
memset(address(theGroup),0,size(theGroup))
BTW much easier without a recursion, just iterate over group fields one by one and CLEAR those that are a GROUP (and optionally HOWMANY > 1).
Interesting idea. For his Group it would work.
It would not work well if the Group contained the typical Clarion STRING types as they are not blank when filled with Chr(0).
It would work for CSTRING, PSTRING and all the numeric types. I think ASTRING is a LONG so it should work.
Thanks ! This is a beautiful and correct solution to my question.
I checked the nested GROUPS, arrays and ANY fields - everything is OK !
I need to learn how to make such code on my own ā¦
great thanks Genricke - glad you appreciated it - it is not everyday that someone comments that your code is ābeautifulā
I guess everyone has their own idea of beauty, but by chance I was recently reading a book that may be of interest:
Beautiful Code: Leading Programmers Explain How They Think
Edited by Andy Oram and Greg Wilson
You can often learn from reading other peopleās code and this book has contributions from 33 different developers. The foreword mentions:
In May 2006, I asked some well-known (and not so well-known) software designers to dissect and discuss the most beautiful piece of code they knew. As this book shows, they have found beauty in many different places. For some, it lives in the small details of elegantly crafted software. Others find beauty in the big pictureāin how a programās structure allows it to evolve gracefully over time, or in the techniques used to build it.
Thanks for the recommendation - Iāll try to find such a book.
I have such a desktop book with almost 900 pages.
There are also a lot of examples of beautiful code in it.
And it happens to be available as a PDF download!
Iāll definitely be having a browse, it will make an interesting change from the SciFi Iām reading ATM!
Ive never found a device thats easy on the eyes, and legible to read electronic txt. Still prefer paper.