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
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}
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.
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!
ReplyDeleteThank you Ana, for visiting my blog. wish you all the best too..
ReplyDeletemantab 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?
ReplyDeletesobat....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@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)
ReplyDeleteArbitter : Ok :-)