Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging code in Delphi XE

I am a long time Delphi dev and in the past I use a third party tool for logging and debugging while developing (called Smart Inspect) however now that I've upgraded to Delphi XE I want to try and use the IDE for debugging.

My question is, given a function like

procedure MyFunction;
var
    str : string;
begin
    str := 'Foo';
    //Debug, show value of str?
    str := AnotherFunction(str);
    //Debug, show value of str?
end;

how can I debug and get the value of str, without doing stupid things like showmessage(str);

if there is a video somewhere (or article) then I am more than happy to read.

Is there a way to watch/output the value of variables.

like image 921
Wizzard Avatar asked Nov 29 '22 19:11

Wizzard


2 Answers

If you want to use the IDE Debugger only, then do the following:

  • put a breakpoint somewhere
  • right click on the breakpointr circle and choose "Breakpoint Properties ..."
  • press "Advanced" button to show more options
  • uncheck "Break" checkbox
  • then use "Log message" and "Eval expression" edit boxes to enter trace values

Such messages will be send to "Event Log" debugger pane. Right click on the pane and choose "Properties". There you can filter ("Messages") / hilight ("Colors") the trace messages as you whish.

like image 71
da-soft Avatar answered Dec 06 '22 17:12

da-soft


Well, Delphi XE comes with CodeSite logging, but I get the feeling you're talking about the debugger itself.

If you place a breakpoint in a routine, it will break to the debugger when it hits it. From there, you've got a Local Variables pane and a Watches pane along the left side of the IDE. Local Variables will show the value of all locals, and Watches lets you set up expressions whose value it will keep track of.

You can also get something similar to a watch, but with more detailed information (especially for structured types such as objects) by using Inspect (Alt-F5). Also, the Evaluate/Modify (Ctrl-F7) will allow you to type in expressions and evaluate them. It's not quite as detailed as Inspect, but it gives you a lot more flexibility.

If you familiarize yourself with these tools, you'll find debugging much easier.

like image 28
Mason Wheeler Avatar answered Dec 06 '22 17:12

Mason Wheeler