Delphi Tutorials »

Registry as Delphi INI-File -- part 2

Title 1

In our previous lesson Registry as Delphi INI-File -- part 1, we wrote this very basic example:

program ConsoleTest; 
{$APPTYPE CONSOLE}
uses SysUtils;

begin
  WriteLn('Program ConsoleTest is running.');
  WriteLn('Press the ENTER key to stop');
  ReadLn;
end.

Let's have a look at the meaning of the different keywords in the source code:

  • program means that this unit is the program's main source unit, the .DPR file. This keyword is followed by the name of the project file, without the extension .DPR.
    When you compile a project, Delphi uses this for the name of the EXE file that it creates.
  • $APPTYPE controls whether to generate a console application or a graphical UI application (GUI = Graphical User Interface). Here, the {$APPTYPE CONSOLE} directive tells the compiler to generate a console application.
  • uses is followed by a list of all the units that the unit ConsoleTest uses, the other units that are part of the project.
    We see that Delphi included the SysUtils unit. Also another unit is included, the System unit, but since System is included in every Delphi program, it's not necessary to mention it in the uses directive.
  • In between the keywords begin and end you add your code.
    Note that the last end keyword is always followed by a dot character -- also called point, period, or final stop. As you've probably guessed ;) this indicates the end of the project file.

Handling Input and Output

In a console application, you don't use VCL controls for input and output. Communication with the user is handled with console Read and Write commands:

  • WriteLn displays a message at the console, followed by an end-of-line code that positions the text cursor at the beginning of the next line.
    Example: display the line of text Program ConsoleTest is running :

    WriteLn('Program ConsoleTest is running');
  • ReadLn inputs keystrokes from the console, until the ENTER ("return") key is pressed.
    Example: read data until Enter is pressed and put in variable S:

    ReadLn(S);

    Example: simply wait until Enter is pressed:

    ReadLn;
  • Write displays data at the console without an end-of-line.Thus, the ouput of the next Write command will appear directly after the displayed text.
    Example: display 3 strings on the same line:

    Write('one ');   // note the space after the word
    Write('two ');   // note the space after the word
    Write('three');

  • Read can be used to directly input data to one or more variables. The Read command waits until the number of data values that are typed (separated by spaces, if more than 1 value) is equal to the number of variables provided. Sounds complicated, doesn't it? That's why Read isn't used often, most input is done with ReadLn.
    Example to input a single character to variable C, given that C is of type "char" (press ENTER afterwards) :

    Read(C);


« Part 1: Registry as Delphi INI-File -- part 1   Part 3: Registry as Delphi INI-File -- part 3 »

 

TOP   DelphiLand Club  DC Library  Forum  Forum Archives 
Crash Course Delphi  Tips  Source Code  Downloads  Links

© Copyright 1999-2018 
Studiebureau Festraets