Delphi Journey Hello World

I’m trying to do the Delphi Pascal journey (I used to be a Pascal programmer years ago then my career went a different direction. Wanted to just get back to it for fun.). I’m just trying to do the Hello World exercise. The exercise say you can’t do it in the on-line editor. So I downloaded the Delphi 12 Community Edition and installed it. Then I downloaded the exercise and installed with the CLI per instructions. When I try to compile it says
“[dcc32 Fatal Error] HelloWorld.dpr(15): F2613 Unit ‘DUnitX.Loggers.Console’ not found.”

I have a feeling I missed installing some packages somewhere. Any suggestions on where to even start looking?

What does your code look like at the moment?

Also see Fatal Error while solving Hello, World!

program HelloWorld;

{$IFNDEF TESTINSIGHT}
{$APPTYPE CONSOLE}
{$ENDIF}{$STRONGLINKTYPES ON}
uses
System.SysUtils,
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX,
{$ENDIF }
DUnitX.Loggers.Console,
DUnitX.Loggers.Xml.NUnit,
DUnitX.TestFramework,
uHelloWorldTests in ‘uHelloWorldTests.pas’,
uHelloWorld in ‘uHelloWorld.pas’;

var
runner : ITestRunner;
results : IRunResults;
logger : ITestLogger;
nunitLogger : ITestLogger;
begin
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX.RunRegisteredTests;
exit;
{$ENDIF}
try
//Check command line options, will exit if invalid
TDUnitX.CheckCommandLine;
//Create the test runner
runner := TDUnitX.CreateRunner;
//Tell the runner to use RTTI to find Fixtures
runner.UseRTTI := True;
//tell the runner how we will log things
//Log to the console window
logger := TDUnitXConsoleLogger.Create(true);
runner.AddLogger(logger);
//Generate an NUnit compatible XML File
nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
runner.AddLogger(nunitLogger);
runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests;

//Run tests
results := runner.Execute;
if not results.AllPassed then
  System.ExitCode := EXIT_ERRORS;

{$IFNDEF CI}
//We don't want this happening when running under CI.
if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
begin
  System.Write('Done.. press <Enter> key to quit.');
  System.Readln;
end;
{$ENDIF}

except
on E: Exception do
System.Writeln(E.ClassName, ': ', E.Message);
end;
end.

This does not seem to be “your code” but perhaps code that was delivered to facilitate the tests.

My code looks like this:

program hello;

uses crt;
BEGIN
  writeln('Hello World!')
END.

This should have been a “simple” replacement of what was there that was failing to what needs to be there to pass. (This is also from when we were putting this track up, so may be out of date.).

It’s not my code - it’s the code that came with the Delphi Exercism Hello World project. I was just trying to make it execute. That’s the goal of this first exercise. Yours is WAY simpler! I will try it. I’m also re-installing the RAD Studio. Turns out I may have not selected all of the necessary options so I’m going to see if that helps also.

Do not replace the code that was delivered, except for the code in hello.pas. All other code there is support code and should be good. No need to modify it.

To be clear, that file should look like this:

unit uHelloWorld;

interface

  function Hello: string;

implementation

function Hello: string;
begin
  result := 'Goodbye, Mars!';
end;

end.

The string you need to change hopefully being obvious.

I solved it in two different ways and I do not remember exactly how it was delivered. There is some freedom, but you will hopefully only have to edit the string to have the tests pass.

This exercise is more “orientation and setup” than actually solving the programming problem itself.

Going through the testing docs for this track, it seems a PR might be warranted to clarify the files given to the student in delphi/docs/TESTS.md at main · exercism/delphi · GitHub. I think it was written before it became commonplace to provide stub implementations for students so students don’t need to create their own Pascal solution files.

I agree, I do not remember if I had outright created the hello.pas file or did the modification in place for uHelloWorld.pas. I believe either will work, though, and there may not need to be a “create a file” step here.

Hopefully Ryan is monitoring here.

CC @rpottsoh

1 Like

I reinstalled Delphi 12 Community Edition - and based on kotp’s comments I found the uHelloWorld.pas file and opened it. Made the slight edit. I don’t get any compile errors and something flashes on the screen - I’m assuming that’s the message. Not sure why it doesn’t stay on the screen. I also tried kotp’s brief code above. The compiler fails on “uses crt;” saying it "F2063 Could not compile used unit ‘crt’ at line 3 (3:6).

btw, the code that I pasted above is what opens in the RAD when I open the “HelloWorld” project.

thanks for everyone’s help.

1 Like

Hello - just a note to say thanks again. The re-install solved the dUnitx issue and I finally figured out that I needed to run the executable from the command line to see the output, rather than running it from the RAD environment. I’m sure I’ll have more questions, but appreciate everyone’s help.

3 Likes

Feel free to mark a solution here, so others know.

And looking forward to seeing you around the Exercism Community!

1 Like

There is another way you can use so that you do not have to run it from command line every time:
Put a ReadLn; just in the line before the end.
This will keep the console window of your application open until you press enter.

If you used in the middle of your code you can also use it to wait there until you press enter and an extended form of that can be used to read in user input.