Jump to content
std_usr

Quick debug variables?

Recommended Posts

Hello,

I'm trying to switch from Python to Delphi and, for quick debugging, I slightly miss Python's print() function, which enables you to print whatever type variables. For example, the following

print(int_var, str_var, dict_var)

prints integer, string, dictionary type variables in one go, so I don't have to convert each variable to string and concatenate them.  Could you suggest me a method/function/tool/whatever to achieve similar functionality (in VCL application)?

Edited by std_usr

Share this post


Link to post

Look at the Format function, it can be used to compose a string from values/variables using a template string with placeholders, taking the values to insert via an open array parameter. That covers all standard simple datatypes, but complex types like objects, arrays, dictionaries usually have no default method to convert their content to a string (although some have a ToString method, natively or through class or record helpers). For your own classes you can override the ToString method inherited from TObject, for instance.

Share this post


Link to post

Hi...:classic_cool:

Quote

I slightly miss Python's print() function

In Delphi is debugging easier... You set breakpoints in the editor. The debugger holds at this line.  The debugger shows variables or a complete object in a hint.

See: https://www.youtube.com/watch?v=eqs27gB7Zms

Edited by haentschman
  • Thanks 1

Share this post


Link to post

You may also have a look into CodeSite, which allows similar things in a more convenient way. The Express version can be installed via GetIt,

Share this post


Link to post

Actually Delphi has WriteLn which does exactly what Python's print does (for simple types, no idea whether Python's print can handle complex types)

Unfortuntately WriteLn writes to the console which usually doesn't exist in GUI programs so it will result in an exception.

Edited by dummzeuch

Share this post


Link to post
37 minutes ago, dummzeuch said:

Actually Delphi has WriteLn which does exactly what Python's print does

Writeln is a joke compared to Pythons print. You can pass any object to print and it then depends on which methods the object implements what gets printed (see https://stackoverflow.com/q/1535327/587106)

And yes, almost all library types implement such methods so you can simply pass arrays, lists or dictionaries to print and get their content printed out.

Edited by Stefan Glienke
  • Like 1

Share this post


Link to post

So I experimented with all the above stuff you mentioned, but setting a breakpoint and checking the variable is probably the simplest/fastest way. Thanks again )

Share this post


Link to post

Nobody seems to have mentioned watches yet. If you want to keep a eye on a value at various places, a watch is the way to go.

Edited by dummzeuch

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×