How determine what causes a Lost Focus event

Something in my app causes a textField to lose focus (triggering a bunch of other things). There are quite a lot of possibilities to track through by turning stuff on and off. Is there an easier way to find out what it is that is gaining focus and causing the loss on the textField?

Have you tried setting a breakpoint in the event to examine the stack? (That may not show you, but it’s where I’d start.)

Yes, that was the initial thought but the stack just shows the item that has lost the focus - it doesn’t show the previous event that caused that loss.

However, by trial and error I have tracked down the errant piece of code and exterminated it. I just thought I might be missing a trick to know what had picked up the focus.

Focus issues are notoriously hard to debug. You usually have to resort to trial and error.

In big projects, I find it useful to create subclasses of each control and set my window controls to that subclass. That lets you change the behavior of all of your controls at once so you can, for example, implement the GotFocus event in the super so it logs before it passes it down to the subclass.

2 Likes

If you don’t have too many controls on the window, doing a system.debuglog in each getFocus, and in your TextField LostFocus the same, will show you when, and which control snatches focus.

Subclassing as described by Kem would make that even easier.

2 Likes

Thank you - good ideas.