Friday, 23 April 2010

Delphi Tutorial # 6

Console Application 

Before we go further with visual programming, it is important to understand the basic element of Delphi. In the first tutorial about, I have mention that a console application is a DOS (Disk Operating System) application. It is a non Windows application. Using console programming, you can focus on the codes only. Meanwhile you can forget about visual programming, and learn about Pascal language.

To make a console application, choose File – Close All (if thee is still a form in IDE). Then choose File – New, select Console Application. Delphi will show Project1.dpr window :

Declare constants and variables after uses SysUtils;

  const

   length : integer = 12;

   width : integer = 8;

  var

   area : integer;

Insert user code between begin …. end.

  area := length*width;

  writeln('Length of rectangle = ',length);

  writeln('Width of rectangle = ',width);

  writeln('The area = ',area);

  readln;

The complete codes of Project1.dpr :

  program Project1;

  {$APPTYPE CONSOLE}

  uses

   SysUtils;

  const

   length : integer = 12;

   width : integer = 8;

  var

   area : integer;

  begin

   // Insert user code here

   area := length*width;

   writeln('Length of rectangle = ',length);

   writeln('Width of rectangle = ',width);

   writeln('The area = ',area);

   readln;

  end.

Run the program, and the result is :

The last code readln; is for delaying program until you press Enter button.

Comment

// Insert user code here is an example of comment. Comment can be written in three ways :

-         Written between { }

-         Written between * *

-         Begun with // like the example above

Assigning a value to a variable

From the program above, we assign a value to area variable using assignment operator :=. The syntax is :

    variable := value;

so the code is :

    area := length*width;

Go to Previous Tutorial or Next Tutorial

4 comments:

  1. blog ini memang kerenz tutorialnya yang nichenya unik tentunya memiliku pangsa tersendiri, tapi ya harus sabar karena tutorial yang semacam ini memang peminatnya kurang begitu banyak, karena banyak orang yang setba praktis he he he...terimakasih atas pencerahannya.

    moga sukses selalu

    ReplyDelete
  2. aq g ngerti wes bahasa pemropograman gini, ilmu q belum nyampe'

    ReplyDelete
  3. @Pakde : Thank you for your encouragement.
    @Rizky : We can learn together then.

    ReplyDelete
  4. s The best and a lot of secret drop-shipping suppliers in the world which will provide your products globally available for you directly to your customers doors. Also get the best drop-shipping manufacturer on your organization.

    ReplyDelete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.