Uniface on GitHub
Fixes and Updates
Removing occurrences inside a forentity for the same entity is described as not recommended in the documentation.
endfor The following code wouldn't achieve much on its own, but is the general act of changing vList inside the forlist also unsupported or not recommended? I have seen similar code in use and while I think it looks risky, I'd like to know if it is actually supported or not.
while (vList != "") forlist vItem, vIndex in vList
if (<condition>) delitem vList, vIndex break endif endfor ; More code endwhile
Equally, items could be added to vList within the loop, instead of being deleted, is this also unsupported?
If unsupported, could this be added to the documentation so that this would be clear to developers?
In the doc for forlist it says:
"The Index can be altered by the code in the loop, which enables you to conditionally make changes in the loop as it executes."
So this will actually work:
forlist vItem, vIndex in vList
if (<condition>) delitem vList, vIndex vIndex =- 1 endif endfor
The same is true for adding items to a list. You just have to make sure that the value of Index is updated accordingly.
I hope this helps.
Kind regards,Daniel Iseli
If you first do a count of items in your list or entity, you could then use a "for" loop setting the StartValue to list / entity count, EndValue to 1 and StepValue to -1 to traverse the list/entity from back/last to front/first.
When you need to clean an entity discard-ing/remocc-ing occurrences or when you need to clean a list with delitem the best choice would be to navigate your entity or your list backward from the end to the start.
Unfortunately forentity and forlist do not enable (yet!) going backward while looping.
I've opened a wish on the subject that can be found at this page while being logged in; if it is also a wish for you let support to know it to raise priority on its implementation.
Ah, ok, you can manually change the list but you must then manually update the index.
I think the documentation would benefit from being clearer on this, perhaps with an example, as it's not obvious that "conditionally make changes in the loop" means manually change the list.
Thanks. On each page of the Uniface Library there is a handy link for providing feedback:
"Send feedback about this topic to Uniface."
© 2021 Uniface Privacy & Cookies | Privacy Statement | Legal