Wednesday 14 April 2010

Delphi Tutorial # 5

Program Structure

A program is composed of three elements :

- Program Title

- Uses Clauses

- Declarations and Statements

Program title is the name of the program. Uses clauses include units that are used in the program. Declarations and statements are codes that will be executed by computer.

You can see an example of Delphi program structure in Delphi Tutorial # 2. See the codes project1.dpr file  below :

    program Project1;

    uses

      Forms,

      Unit1 in 'Unit1.pas' {MyForm};

    {$R *.RES}

    begin

      Application.Initialize;

      Application.CreateForm(TMyForm, MyForm);

      Application.Run;

    end.

The example above does not have declarations. Declaration is where we define constants, types, variables, procedures and functions. The structure of declarations is shown below :

     Const

           {constants list}

     Type

          {types create by user}

     Var

          {variables list}

          {functions and procedures}

Function is a routine that can be called by the program and will return a value. Procedure is a routine that does not return a value.

A program is usually formed by some source code modules that called units. A unit consist some routine (functions and procedures). It is saved as a unit file (.PAS). The structure of a unit is shown below :

       Unit unitname;

       Interface 

       Uses {units}

       {interface}

       Implementation

       Uses {units}

      {implementation}

       Initialization

       {Initialization}

       Finalization

       {Finalization}

       End.

The example of a unit is unit1.pas file :

    unit Unit1;

    interface

    uses

      Windows, Messages, SysUtils, Classes, Graphics, Controls,           Forms, Dialogs, StdCtrls;

    type

      TMyForm = class(TForm)

        Label1: TLabel;

        ExitButton: TButton;

        procedure ExitButtonClick(Sender: TObject);

      private

        { Private declarations }

      public

        { Public declarations }

      end;

    var

      MyForm: TMyForm;

    implementation

    {$R *.DFM}

    procedure TMyForm.ExitButtonClick(Sender: TObject);

    begin

     Application.Terminate;

    end;

    end.

Go to Previous Tutorial or Next Tutorial

5 comments:

  1. Hello Ari, thanks for your visit and for the comment left. I picked up those pictures free on internet.. so I think there's no problem to use them in a non-commercial manner. Wish you all the best!

    ReplyDelete
  2. Thank you Ana, for visiting my blog. wish you all the best too..

    ReplyDelete
  3. mantab sobat, aq masih belum ngeh dengan delphi...klo bisa share software nya juga dong, oh ya delphi itu prinsipnya sama ndak dengan VB atau SQL?

    ReplyDelete
  4. sobat....klo tidak keberatan saya nantikan kehadiranya di blog saya dan kesediaanya untuk bergabung di dalam forum, nampaknya delphi adalah materi baru yang belum kami miliki deh....

    ReplyDelete
  5. @Aditya : Delphi is quite the same with VB, it's an OOP and a visual programming. But Delphi based on Pascal Language. SQL is for database. Delphi and VB is usually for creating a user interface that is connected to a database server (interbase, mysql, firebird etc)
    Arbitter : Ok :-)

    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.