Steve
Steve

Reputation: 6470

Debugging Window Message handling in Delphi

I have an application that handles the the CM_DIALOGKEY message on it's main form.

procedure CMDialogKey(var Message: TCMDialogKey); message CM_DIALOGKEY;

This worked up until some point recently, but I can't figure out at what point something was changed, and more importantly what. If I create a blank application, put in the message handler above then the message is handled and I can do things on certain keystrokes. Somewhere along the line some code must have been added that handles a message and doesn't propogate that message, but for the life of me I can't figure out what. Any ideas on how to go about debugging this? Breakpoints are obviously out of the question, unless someone has an idea of a breakpoint somewhere specific.

Upvotes: 0

Views: 667

Answers (1)

David Heffernan
David Heffernan

Reputation: 613461

Any ideas on how to go about debugging this?

Here's how I would go about debugging this:

  1. Use your version control system to isolate the commit that changed behaviour.
  2. Using the last commit that worked as intended, set a breakpoint in CMDialogKey.
  3. Run the program until the breakpoint triggers and make a copy of the call stack in this state.
  4. Switch to the first commit that does not work. Now set a breakpoint higher up the call stack from step 3 which does trigger. You may need to work a little to find such a place, and you may need to use a conditional breakpoint. For instance you might need the condition Message.Msg=CM_DIALOGKEY.
  5. Now step forwards and find the point at which the execution diverges from the call stack seen in step 3.

At this point you should have isolated the behaviour change and be in a position to investigate a solution.

Upvotes: 1

Related Questions