3

I am working on a Delphi project for the first time, I used to develop on Java.

Is there a way to print in delphi's console like in java.

System.out.println("Message");

which I used to test code and find bugs (primitively).

Arioch 'The
  • 15,799
  • 35
  • 62
sandiego
  • 151
  • 1
  • 4
  • 10
  • Your question can be intepreted in at least two different ways. RRUZ talks about console-mode applications, while I talk about the IDE's event log (in any type of application). What exactly do you mean by "Delphi's console"? – Andreas Rejbrand Dec 17 '13 at 21:07
  • @AndreasRejbrand `System.out.println()` is the process console. `Writeln` in Delphi. `cout` in C++. `Console.WriteLine()` in C#. `print()` in Python. etc. etc. – David Heffernan Dec 17 '13 at 21:10
  • @DavidHeffernan: Thanks for clarifying. I was just about to look the Java stuff up. – Andreas Rejbrand Dec 17 '13 at 21:11
  • `System.out.println()` shows in most IDEs when run in debug mode. I think the OP may want `OutputDebugString` to view messages when the application is run inside of Delphi IDE. – Marcus Adams Dec 17 '13 at 21:37
  • @Marcus: I also thought so, and wrote that as an answer half an hour ago. But most people believe the OP is after `Writeln`. But I'll undelete my answer so the OP can choose for himself. – Andreas Rejbrand Dec 17 '13 at 21:38
  • Yeah, JVM has a debug console too. – Free Consulting Dec 17 '13 at 22:24

5 Answers5

9

You must use Writeln (only for console applications).

{$APPTYPE CONSOLE}
begin
  Writeln('Hello');
  Readln;
end.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • 1
    You can also call [AllocConsole](http://msdn.microsoft.com/en-us/library/windows/desktop/ms681944%28v=vs.85%29.aspx) in a VCL application to use Writeln. Don't know about Firemonkey but it should work aswell on at least Windows. – Stefan Glienke Dec 18 '13 at 06:44
6

If you want to put a string in the IDE's event log, you can use the OutputDebugString function.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
3

I usually use the following code for "debugging" my programs.

    showmessage('Hello World');

That's how i do it.. :)

1

If you want something similar to Java console, you can use CodeSite, which uses an independent viewer

enter image description here

Another similar tool is TraceTool

enter image description here

More logging libraries on this question - Which logging library is better?

Community
  • 1
  • 1
RBA
  • 12,337
  • 16
  • 79
  • 126
0

For debugging messages there is also the GExperts console to which you can write using the SendXXX procedures in GX_DbugIntf. This unit is part of the GExperts source code which is available on SourceForge.

dummzeuch
  • 10,975
  • 4
  • 51
  • 158