std_usr 0 Posted October 7, 2019 (edited) 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 October 7, 2019 by std_usr Share this post Link to post
PeterBelow 238 Posted October 8, 2019 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
haentschman 92 Posted October 8, 2019 (edited) Hi... 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 October 8, 2019 by haentschman 1 Share this post Link to post
Uwe Raabe 2057 Posted October 8, 2019 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
dummzeuch 1505 Posted October 8, 2019 (edited) 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 October 8, 2019 by dummzeuch Share this post Link to post
Stefan Glienke 2006 Posted October 8, 2019 (edited) 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 October 8, 2019 by Stefan Glienke 1 Share this post Link to post
std_usr 0 Posted October 8, 2019 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
dummzeuch 1505 Posted October 8, 2019 (edited) 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 October 8, 2019 by dummzeuch Share this post Link to post
haentschman 92 Posted October 9, 2019 (edited) Hi... Quote simplest/fastest way ...it is the only way. watches... More information: http://docwiki.embarcadero.com/RADStudio/Rio/en/Overview_of_Debugging Edited October 9, 2019 by haentschman Share this post Link to post