# Bug in #For(%Symbol) when using #Delete(%Symbol) skips some

**URL:** <https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035>\
**Category:** questions\
**Tags:** templates, bugs\
**Created:** [April 9, 2026, 11:14am UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035 "2026-04-09T11:14:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [April 9, 2026, 11:14am UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/1 "2026-04-09T11:14:37Z")

</div>

Found a bug in the #For() template command which intermittently doesnt delete all instances.

Its like the internal counter gets messed up after the delete, ie record 2, delete record 2, record 3 becomes record 2 and then the #For fetches record 3, skipping the replacement record 2.

As #For is mainly used with builtin symbols which cant be deleted, this might explain why it exists.

```clarion
#For(%MultiSymbol)
#Delete(%MultiSymbol)
#EndFor

```

Wont delete all instances of the %MultiSymbol.

---

<div class="post-metadata">

**Author:** ![BoxSoft](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/3d9bf3/32.png) [@BoxSoft](https://clarionhub.com/u/BoxSoft)\
**Post date:** [April 9, 2026, 2:20pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/2 "2026-04-09T14:20:06Z")

</div>

I wouldn’t call that a “bug”, but rather a typical quirk of looping logic. That’s why so many of my loops are written to go backwards, which you could do with the `Reverse` attribute:

```clarion
#For(%MultiSymbol),Reverse
  #Delete(%MultiSymbol)
#EndFor

```

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [April 9, 2026, 4:09pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/3 "2026-04-09T16:09:59Z")

</div>

The docs dont allude to this quirk so I rehashed the code with a few more lines.

```clarion
#Declare( %Found, Long ) 
#Loop 
#Set( %Found, 0 ) 
#For( %MultiSymbol ) 
#IF( %MultiSymbol ) 
#Delete( %MultiSymbol ) 
#Set( %Found, 1 ) 
#EndIF 
#EndFor 
#IF( NOT %Found ) 
#Break 
#EndIF 
#EndLoop 

```

I’ll give the reverse a go as I can see how that was probably invented for this situation. 😁

---

<div class="post-metadata">

**Author:** ![BoxSoft](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/3d9bf3/32.png) [@BoxSoft](https://clarionhub.com/u/BoxSoft)\
**Post date:** [April 9, 2026, 5:25pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/4 "2026-04-09T17:25:27Z")

</div>

Yeah, the `REVERSE` attribute is a bit more elegant. 😉

BTW, here are a couple other less straightforward ways to skin the cat:

```clarion
#LOOP
  #SELECT(%MultiSymbol, 1)
  #IF(INSTANCE(%MultiSymbol)=0)
    #BREAK
  #ENDIF
  #DELETE(%MultiSymbol)
#ENDLOOP

```

```clarion
#LOOP,WHILE(ITEMS(%MultiSymbol))
  #FOR(%MultiSymbol)
    #DELETE(%MultiSymbol)
  #ENDFOR
#ENDLOOP

```

The template language is wonderfully flexible, and of course _flexibility_ breeds _complexity_.

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [April 9, 2026, 6:31pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/5 "2026-04-09T18:31:23Z")

</div>

I havent added a lot of commands to my template builder yet, but there’s enough there for it to write my class writing template, so its very bare bones still without any “compound” templates, ie templates which do things like the above code examples with minimal prompt input and I’m only writing classes to remove huge chunks of code from the embeds of an app, to keep things simple.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [April 9, 2026, 9:27pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/6 "2026-04-09T21:27:48Z")

</div>

> [@BoxSoft](#):
>
> ```auto
> #LOOP,WHILE(ITEMS(%MultiSymbol))
> #FOR(%MultiSymbol)
> #DELETE(%MultiSymbol)
> #ENDFOR
> #ENDLOOP
> 
> ```

Seems good to also `REVERSE` in that code so that it is unlikely the `While(Items())` will be True on the 2nd loop:

```clarion
#LOOP,WHILE(ITEMS(%MultiSymbol))
  #FOR(%MultiSymbol) ,REVERSE
    #DELETE(%MultiSymbol)
  #ENDFOR
#ENDLOOP

```

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [April 10, 2026, 2:58am UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/7 "2026-04-10T02:58:33Z")

</div>

Well should have this Class Writing template finished by the weekend ready for me to test its code with the compiler.

I think it cover’s all the bases, with scope for future data types, if any…

Cant decide whether to hook some of these Ai’ LLM’s into it to make writing the class code even easier. Any recommendations? 😁

 ![Screenshot 2026-04-10 034422](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/2X/7/7fc508504e1a9035288e58b98443b05155fc571b.jpeg)

---

<div class="post-metadata">

**Author:** ![BoxSoft](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/3d9bf3/32.png) [@BoxSoft](https://clarionhub.com/u/BoxSoft)\
**Post date:** [April 10, 2026, 2:11pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/8 "2026-04-10T14:11:35Z")

</div>

Agreed. My point with those two additional examples was that they were less efficient/elegant ways to get the job done. The simple `#FOR(...),REVERSE` approach is absolutely the best choice.

However, if you just want to delete all instances of the multivalued symbol, then obviously `#PURGE(%MultiSymbol)` is even better. The `#FOR + #DELETE` loop is necessary only if you need to do something with each entry before deleting it.

That brings up another interesting point: I’ve always been confused about the difference between `#PURGE` and `#FREE`. The (non-template) Clarion language uses `FREE(Queue)`, so one could expect that `#FREE(%MultiSymbol)` is the way to go. However, the docs indicate that `#FREE` _clears_ all instances, whereas `#PURGE` _deletes_ them. Therefore, I’ve always used `#PURGE`, just in case. I suspect they do the same thing, but I’ve never gotten around to testing it. 🙄

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [April 10, 2026, 7:09pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/9 "2026-04-10T19:09:43Z")

</div>

They are like #Insert and #Invoke…

The only difference I can see, is the #Invoke help suggests it can bring in #group code from different #template’s, at least thats how it reads to me, but like you I’ve not tested either and I cant find any example’s in the shipping templates to back that up, but I’ve only done a cursory check.

---

<div class="post-metadata">

**Author:** ![BoxSoft](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/3d9bf3/32.png) [@BoxSoft](https://clarionhub.com/u/BoxSoft)\
**Post date:** [April 10, 2026, 8:01pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/10 "2026-04-10T20:01:48Z")

</div>

That’s not quite the same, as the purpose of #INVOKE is rather special.

Let’s start with `#INSERT` and `#CALL`, which are more similar to each other:

`#INSERT` is the traditional command, and indicates to generate the named group with its code left-justified at the column position of the `#INSERT`. For example, if the `#INSERT` is position in column 5, then the `#GROUP` code will appear in column 5. If the code in the `#GROUP` itself is indented, then that will be added to the `#INSERT` column position. You can disable this indentation with the `NOINDENT` attribute.

`#CALL` was added later. It can call a `#GROUP` like `#INSERT`, but the generated group code will ignore the column position of `#CALL`, like `#INSERT(...),NOINDENT`.

Generally speaking, I use `#INSERT` to call a `#GROUP` that I expect to generate code, while I use `#CALL` to execute a `#GROUP` that contains pure logic (no generated code). I break that rule occasionally, mostly when I use `#INSERT` in place of `#CALL` (because it was always OK to use `#INSERT`).

With both `#INSERT` and `#CALL`, the name of the #GROUP must be _hard-coded when the template is written_:

```clarion
  #INSERT(%SomeGroup) #!Generates code starting at column 3
  #CALL(%SomeGroup) #!Generates code started at column 1

```

#CALL can also be used to call a #GROUP that returns a value (although I believe they added that ability to `#INSERT` as well):

```clarion
  #DECLARE(%CapturedReturnValue)
  #CALL(%SomeGroup), %CapturedReturnValue

```

`#INVOKE` is different in a very important way. It’s used to call a `#GROUP`, where the name isn’t known until the code is generated (long after the template was written). You have to assign the name of the `#GROUP` to a runtime symbol, then pass that symbol to the `#INVOKE` command:

```clarion
  #EQUATE(%SomeGroupName, '%SomeGroup(ABC)')
  #INVOKE(%SomeGroupName)

```

`#INVOKE` can also specify a return value be captured.

I believe the chain name is optional with all of them. Parameters are passed the same for all three commands.

Bottom line, here’s how I choose to use them:

- If the `#GROUP` I’m calling will generate code, I use `#INSERT`.
- If if’s pure logic with no generated code, I use `#CALL`.
- If I don’t know the name of the `#GROUP` until generation time (very special), then I use `#INVOKE`.

FYI, I have only two instances of `#INVOKE` in all of my template sets. It’s typically used to generate virtual methods based upon reading of classes at generation time.

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [April 10, 2026, 11:18pm UTC](https://clarionhub.com/t/bug-in-for-symbol-when-using-delete-symbol-skips-some/9035/11 "2026-04-10T23:18:47Z")

</div>

> [@BoxSoft](#):
>
> ```auto
> #EQUATE(%SomeGroupName, '%SomeGroup(ABC)')
> #INVOKE(%SomeGroupName)
> 
> ```

Yeah I did note that the symbol used in #Invoke could be used like a variable to call another #group symbol, but I havent had to use #Invoke yet.

 ![Screenshot 2026-04-11 000255](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/2X/5/51483726da24ab15f210617df7ea3ec47f9a93ca.jpeg)

There’s alot of template commands I’ve not written template’s for in my Template Builder, I’ve only used 64 commands to write my template builder. And those 64 commands are also capable of writing my Class Writer template using only the AppGen and no embed source code.

As the other screenshots have shown, the prompt and control positioning is functional as is the various PROP:XYZ which works with PROP() as seen with the tooltip below.

 ![Tooltips](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/2X/7/7e095d54b64a53d5f0bbe5ac58aa2ef000b280a1.jpeg)

Its so slow going getting the right wording for tooltips…

Edit.  
This is all the Class Writer template looks like inside the AppGen.

 ![Screenshot 2026-04-11 003651](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/2X/d/dc9f103b0ed404d546193e7589735ce0b01d075d.jpeg)

The good thing about this exercise is, I’m smoothing out the template builder so I can then use it to generate code in other languages. I’m thinking a Dot Net Maui template soon… 😁

The #RunDLL means I can call compilers and other CLI stuff now.

> **[.NET Multi-platform App UI (.NET MAUI) | .NET](https://dotnet.microsoft.com/en-us/apps/maui)**
>
> .NET MAUI is a framework used to build native, cross-platform desktop and mobile apps from a single C# codebase for Android, iOS, Mac, and Windows.

Edit.

Would this be a better Tooltip/TLDR description for Implements and Interfaces?

In particular I’m trying to use a real world relatable example of what Interface’s can be used for.

So I’ve used this example which I think is relatable.

> For example, a FileManager Interface, can force a SQL DB Class, ISAM Files Class, and Cloud Data Class to all provide the same methods (procedure’s) to provide identical CRUD functionality.

So the tooltip now read’s

> Tick this option if you want this class to inherit the methods defined in one or more Interfaces.  
> An Interface is a Type definition that dictates the methods this class will/must have and respond to.  
> Think of an Interface as a predefined list of Methods (procedure’‘s) that this class must have and respond to along with this class’‘s other unique method (procedure) name’'s.  
> For example, a FileManager Interface, can force a SQL DB Class, ISAM Files Class, and Cloud Data Class to all provide the same methods (procedure’s) to provide identical CRUD functionality.

See what I mean about trying to get the tooltip wording right… 🙄
