UsersGuide:Chapter 12:Following the Execution of Methods
From Real Software Documentation
Contents |
Following the Execution of Methods
When your code isn’t cooperating or you’re just not sure what is executing and when, it’s helpful to be able to watch your code as each line executes. The Debugger makes this easy. Once the Debugger is displayed, the line that’s highlighted indicates which line of code is about to be executed. When you tell the Debugger to continue, it executes that line and goes on to the next line of code. What it does next depends on the command you give it when you wish to continue. The Debugger Toolbar and the Project menu give you three commands, each of which will execute the current line and then take a different course of action for the next line of code.
Step
Step executes the current line and moves on to the next line. If the current line includes one of your methods, the Debugger executes the method but will not step through the method’s code. When the method is finished executing, the Debugger will continue from the next line of code in the current method. Consider the following code:
Let’s assume that “ToFrench” is a method that translates English to French. If you step through this code using the Step Over menu item, the second line of code is executed, but the Debugger won’t display the code in the ToFrench method. It executes the ToFrench method and continues with the next line of code.
Step In
Step In executes the current line and moves on to the next line. If the current line includes one of your methods, the Debugger displays the method and steps through the method’s code. When the method is finished executing, the Debugger returns to the calling method or event handler and continues with the next line of code.
Step Out
Step Out executes the rest of the method without stopping on each line. This is handy when you have used Step In to step through a method that was called by another method and now wish to continue code execution without stopping on each line. If you entered the current method or event handler using Step In, then stepping out executes the rest of the method and stops on the next line of code in the method that called the method you are stepping out of.
Tracking Method Execution with the Stack
A method or event handler can call another method or event handler which can call another one. This can go on for a while and you may need to keep track of the path of methods that were executed to get you where you are now. The Stack drop-down list does just that. When code execution begins (for example, when a PushButton is clicked), the Stack lists the PushButton’s action event handler. If the action event handler calls a method, that method is added to the top of the list in the Stack when it’s called. If that method calls another method, it is added to the top of the list. Once the current method finishes executing, it is removed from the list as Real Studio returns to the method that called it. It’s called the “Stack” because the methods are “stacked” one on top of the other in the order they were called.
If you need to see the code from a method or event handler called earlier in the stack, click on its name in the Stack drop-down list to display the code for that method in the Code Editor area of the Debugger screen.
| NOTE: The larger the Stack gets, the more memory is being used. If you run out of memory it could be because your stack is so long that it takes up all the memory that has been allocated to the stack. The solution is try to make fewer method calls and use fewer local variables. |
