Sunday, June 12, 2011

1.4 delphi component

1.4 delphi component
After the first attempts to create a simple application program.you may know more about Delphi and feel how easy it is Delphi and sophisticated in making the application program. to be able to master it , of course we must to learn the basics by studying the terms and delphi component it was used to create program.
  • Project
  • Form
  • Unit
  • Program
  • Properties
  • Event


1.4.1 project

project is a collection of forms, units and other matters, or project is the application itself. The main project file is stored in files ending in. dpr. in addition, when you design the project, it will also be automatically created by Delphi numerous files needed project. the files are like:
  • Unit (.pas ) : unit used to store program code, usually associated with the form, but sometimes the unit just a procedure or function that is not related to form.
  • form(.dfm) : used to store all information about form
  • project option (.dfo) : used to store all setting project option
  • Resource (.res) : used to store icons were in the project
  • Backup(.~dp, .~df, .~pa) :used to store backup files project, form, and unit.
1.4.2 Form

[caption id="attachment_1005" align="aligncenter" width="300" caption="form"][/caption]

form is an object that is used as a place of work applications. form-shaped window can be assumed as a paper that can be painted or put other objects into it.

when creating a new application, it will be available a form (Form1) automatically. in making a project we can use more than one form. and the grid is in the form is very useful to adjust the layout of objects in the form.

each form contains the unit. units in the form used to regulate and control form.

1.4.3 Unit

unit is the module code. one program may have one or more units. in Borland Delphi is an integral unit with the form. every form builder then one unit will be created automatically follow. units associated with for this is usually used to organize and engendalikan yag everything related to the form. in addition to units of this type, there are also units that we can make yourself and separate from the form, the unit types in normally set funtion or procedure that is used in applications

function of unit on the aplications include :


  • divide a large applications in a few unit, so that we can edit only certain unit. this can facilitate us design, modification and completion of application.
  • create libraries of functions and procedures, thereby facilitating sharing between aplications.
  • units can be compiled separately from other applications that require similar units. use it without having to rewrite the program code.
1.4.4 program

program built from one or more unit, a program generally have the following structure :
  • Heading : this sections show the name of program.
  • Uses :contains a list of commands that used the program.
  • Block Declarations and Statement : contains of declarations and statements it was used when the program start. this sections must be end with statements END. heading and declarations it is needed when compilation of program .not program implementation.
so we generally writing program such as :

< unit <programname>;
uses<list of unit used in the program>;
<declarations and statement>
end.

to devide statements we use semicolon ( ; )
example 1 :

procedur TForm1.FormCreate(Sender : TObject);
var o,d,e,x :integer;
Begin
o:=1;
d:=2;
e:=3;
x:=o+d+e;
edit1.text:=inttostr(x);
end;
end.

procedure below can we write like this
example 2 :

procedur TForm1.FormCreate(Sender : TObject);
var o,d,e,x :integer;
Begin
o:=1;d:=2;e:=3;
x:=o+d+e;
edit1.text:=inttostr(x);
end;
end.


1.4.5 properti

property is used to determine the settings of an object. an object usually has several properties, which can be arranged directly through the object inspector window or through code . setting properties will determine how the work of the respective object when the program starts. for example , determine the color, frame, data collection etc.

1.4.6 Event

event is the event received by an object, such as click, over, collecting data, etc.

example

procedure TForm1.Button1Click(Sender: TObject);
var awal,akhir :tdatetime;
lama:real;
begin
if button1.Caption='start' then
begin
awal:=time;
edit1.Text:=timetostr(time);
button1.Caption:='stop';
end
else if button1.caption='stop'then
button1.Caption:='finish'
else
application.Terminate;
end;

The above procedure is event click. when button1-clicking the program code lines below it will be implemented. how to create a procedure that will be executed when an object receives events:


  • double click om object.
  • making procedure in the code editor and entered procedure name in the desired event.
  • by selecting the desired object, then select the event window and then double-click onthe right field of event.

 

No comments:

Post a Comment