As I was testing the information in Watch returns the function value only from another unit I had come across a problem with using Debugger, specifically with the Trace Into option.
A) Use the following script in IDE Demo.
If you were to Click on the Trace Into button. It will start the Running of the script and stop at line 8. If you were to click on the Trace Into button 4 more times. It would trace into the _2Text function return to the Main procedure and exit out of the script. From beginning to end you should have clicked on the Trace Into button 5 times.
This is Normal, and expected, behavior.
Unit1:
function _2Text: string;
begin
Result := 'text';
end;
begin
_2Text;
end;
B) Using the following two Unit script in IDE Demo.
With this script the normal expected behavior of using the Trace Into button. Should be the exact same as the example A above. Except that it should trace into the Text function in Unit2.
- The debugger should go to line 5 of Unit1.
- Then Line 3 of Unit2.
- Then Line 4 of Unit2.
- Then Line 6 of Unit1
- Then exit the script.
But the problem is, you end up clicking on the Trace Into button 14 times. The process is as follows:
- Debugger goes to Line 4 of Unit1.
- Then Line 3 of Unit2.
- Then Line 4 of Unit2.
- Then Line 1 of Unit2.
- Then Line 3 of Unit2.
- Then Line 4 of Unit2.
- Then Line 3 of Unit2.
- Then Line 4 of Unit2.
- Then Line 3 of Unit2.
- Then Line 4 of Unit2.
- Then Line 1 of Unit2.
- Then Line 3 of Unit2.
- Then Line 4 of Unit2.
- Then returns to Unit1 as the script ends.
This is not Normal, or expected, behavior.
Unit1:
uses
Unit2;
begin
Text;
end;
Unit2:
function Text: string
begin
Result := 'test';
end;
C) Now if you use the following two Unit script in the IDE Demo. This is a combining of the two previous scripts.
Now, with this script. The normal expected behavior. Is that you should only need to click on the Trace Into button 8 times. And it should trace into the Main procedure, the _2Text function, the Text function, and then exit the script. But, that is not the case. What ends up happening is the following:
- Goes to line 3 of Unit2.
- thru 27. Cycles through the Text function in Unit2. Just like in Example B above.
- Returns to Unit1 where the script ends.
This is not normal, or expected, behavior.
Unit1:
uses
Unit2;
function _2Text: string
begin
Result := 'text';
end;
begin
_2Text;
Text;
end;
Unit2:
function Text: string
begin
Result := 'test';
end;
D) Now use the following two Unit script in IDE Demo.
With the following script, you end up clicking on the Trace Into button 20 times. With the following results:
- Goes to Line 8 in Unit2.
- Goes to Line 9 in Unit2.
- Goes to Line 1 in Unit2.
- Goes to Line 8 in Unit2.
- Goes to Line 9 in Unit2.
- Goes to Line 3 in Unit2.
- Goes to Line 4 in Unit2.
- thru 19 cycles through the Text function in Unit2.
- Returns to Unit1 where the script ends.
Again, This is not normal, or expected, behavior.
Unit1:
uses
Unit2;
begin
_2Text;
Text;
end;
Unit2:
function _2Text: string;
begin
Result := 'test';
end;
function Text: string;
begin
Result := 'test';
end;
The expected behavior for C and D above. Is that the debugger should Trace into the Main procedure. Trace Into _2Text function, then return to the Main procedure. Trace into the Text procedure. And then finally return to the Main procedure before the script ends. It should not matter what units the functions are in.