It's been a long time since I used MFC ... but your problem is simpler than you think:
delete
is used to return memory to the heap, it won't remove text from a CEdit control.
And that's why your app crashes: the chunk of memory you are trying to delete isn't allocated separately with
new
so the system gets confused and everything breaks down.
Instead of
delete
use the CEdit methods to remove the text line:
CEdit Class | Microsoft Learn[
^]
And just as an aside, never delete items from the beginning - always delete from the end and work back.
Why? Two reasons: firstly it eliminates a heck of a lot of unnecessary copying, and secondly, it means you look at every item. If you delete from the start and two items next to each other need to be removed, then removing the first one and incrementing the index means you don't look at the second.
I'd also think pretty hard about what exactly you are doing: why are you removing all the non-empty items? Wouldn't it be more sensible to remove everything in one go since you will end up with an "empty" control either way?