That DoEvents is inside of innerRestoreState routine, which is a recursive routine (it calls itself).
It is also called by a public method, RestoreState, and we cannot know how the user-developer will call this routine (he could call it at bottom of a "calling chain")
So:
1) I think that you should never replace DoEvents with Sleep(0) if it is inside a recursive routine; am I wrong?
2) what happen if it is called by a public method... [second situation described above]?
I've replaced DoEvents with Sleep (with Replace all ....), and get problems.
(I do not remember exactly what, but I think the app has crashed),
so I've been replacing the Sleep(0) back to DoEvents.