Getting Started – Delphi

When the first time you run Delphi, display that appears more or less are as follows:

First appearance of Delphi XE4

First appearance of Delphi XE4

First appearance of Delphi 6

First appearance of Delphi 6

Form

Form is the display of the program that you created. Try to run the program by pressing the F9 key. You will see a program window which is still empty. Of course still empty because you have not added any to them. However, the program has had a behavior as most Windows programs. You can shift its position, modify its size, does minimize, maximize, restore, and close the program by clicking on the cross button on the top right corner of the window. If we use the XE4, the first time we are running Delphi, there has been no application made, so we haven’t been able to run the application by pressing F9. Make in advance by clicking on the menu File>New>VCL Forms Application – Delphi.

Change the appearance of the Form

The Form is an object of the program. Each object of the program has its own behavior. To change the behavior of the object of the program, we can do it through the window of the Object Inspector. This window usually found at the bottom left corner, but if this window is not visible, it can be displayed by pressing the F11.

There are two tabs in the Object Inspector window, Properties and Events. Easily, the properties of the object the program will determine the appearance of the object. While the event will determine how the object will act and react. Actually this explanation is not exactly like so, yet until this step please just consider like so.

The properties that are most important from a Form (or perhaps other program objects) ie are:

Add the program object into the Form

You can add objects of the program into the Form with any object you like as much as you like. Of course the reasoning does not like or don’t like but more in consideration of the needs of the program.

TButton

One of the most important program object is Button. To add object Button into the Form, click the Button component in the Component Palette. After that component appear selected, click on the desired position on the Form and drag to define its size.

Choose TButton to be added to the Form

Choose TButton to be added to the Form

The object of the first Button will automatically be named Button1 with a caption equal with its name. You can change the name or caption property via the Object Ispector. But for now, we don’t need to put much concerns in changing its properties.

As we have discussed above, in addition to the properties, the object has an event, how the object act and react. One of the most important event of the object with the type of TButton is OnClick event, i.e. actions committed by the program if a Button object is clicked. You can fill these events and see what event is owned by a Button through the Object Inspector. But to simply populate the event OnClick of a Button, you can simply double-click on the Button object.

If you double click on a Button object, then you will be taken to the code editor to the event OnClick of the Button object as follows:

procedure TForm1.Button1Click(Sender: TObject);
begin
|
end;

The code for the event is still empty. Now try to add a code into it so that the event is as follows:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Caption:='Clicked';
end;

Run the program by pressing the F9 key. The first time the program is run, then it looks more or less are as follows (depending on the size and position you created):

The first Program with Button

The first Program with Button

If you click on the button, then the text on the button will change.

The first Program after the Button is clicked

The first Program after the Button is clicked

The process that occurs is as follows:

If the button is clicked, then the procedures linked to the event OnClick of the button will be executed. In this case the procedure is procedure TForm1.Button1Click in which there is a command to change the caption property of Button1.

Dot

To refer to a property of an object, first, write the name of the object, followed by a dot, and then followed by the name of its property. So to refer to the caption property from the button object named Button1, then we write it as Button1.Caption.

Assignment Operator

The Assignment Operator is an operator that serves to fill the object on the left side of the sign with the object on the right sign. The Assignment Operator in mathematics is the equal sign (=), but Delphi using colon equals (:=). Between the colon and equal sign must not be separated.

String

String type is a string of characters. Writing strings in Delphi must be enclosed with single quotation marks (use quotation marks that are the same button with double quotation, not quotation marks which are to the left of the 1 key).

Now we can understand the meaning of

Button1.Caption:='Clicked';

as command to populate the property caption (which is a string of characters) of the Button1 object with the string (character string) ‘Clicked’.

Semicolon

Semicolon is used to indicate the end of the program statement. A program statement can be divided into several lines. As long as semicolon is not yet found, then the lines are still regarded as one statement of the program.

TLabel

The Label is a component that serves to display the information in the form of a string. Add this component into the Form below Button1 so it looks like the following figure:

The addition of the Label below the Button

The addition of the Label below the Button

The object name of the first label is Label1 automatically, as well as the captionnya property.

Now, change the command line:

Button1.Caption:='Clicked';

Into:

Label1.Caption:='Clicked';

Run the program and click on the button. What is changed is the text below the button, not the text on the button.

Data type

If we are talking about the program, it cannot be separated from discussion about data types. Basically, there are two kinds of simple and fundamental data types, i.e, the numeric and character type. Numeric type are further divided into several groups. Likewise with character type.

The Data in the program is stored in a storage medium that is called with the variable. Variable with the numeric data type can only receive data in the form of numbers. Similarly, a variable with a type character can only receive data in the form of characters. The more important difference is that the type of numeric can be used for arithmetic operations, while the type karaktier can not. The classification of data types such as this is not a grouping of data types according to the definition of Delphi, but grouping like this is just the way I am merely to simplify the discussion. Gradually, we will improve understanding of the data type.

Details about the data types are as follows:

Numeric data type

There are two kinds of numeric data type i.e. integers and fractional.

Integer Type

Data typeRangeSize
Integer–2147483648..214748364732-bit
Shortint–128..1278-bit
Smallint–32768..3276716-bit
Longint–2147483648..214748364732-bit
Int64–2^63..2^63–164-bit
Byte0..2558-bit
Word0..6553516-bit
Longword0..429496729532-bit
Fractional type

Data typeRangeSignificant DigitSize (byte)
Real482.9 x 10^–39 .. 1.7 x 10^3811–126
Single1.5 x 10^–45 .. 3.4 x 10^387–84
Double5.0 x 10^–324 .. 1.7 x 10^30815–168
Extended3.6 x 10^–4951 .. 1.1 x 10^493219–2010
Comp–2^63+1 .. 2^63 –119–208
Currency–922337203685477.5808.. 922337203685477.580719–208

The Division of the various data types used to gain efficiency. For example, if we are going to keep track of the day in a month that the maximum is 31 days, then we can use the byte data type has a range of 0 .. 255. Although we can use the integer type, but the use of an integer is a waste because the integer takes 32 bits (4 bytes) of memory, while byte requiring only 8 bit.

The assignment between two variable with a different data type will cause the following things:

Characters type

The Data with character type is the data that saves the character from a. ..z, a..Z, 0 .. 9, as well as all the character found on the keyboard. The characters actually also has the ordinal value starts from 0 to 255. It is therefore a character type of data has the same size with byte type. Strings as we have used in the experiment with the caption is a string of characters.

In addition to the types as already mentioned above, there are a lot of another data types. In fact we can also make our own data type.

Variable

Above already mentioned that in order to save the data, we need the storage medium are called variables. Before we can use a variable, first we have to declare it. To declare a variable, we need a keyword var followed by the name of variabelnya, followed by a colon, followed by the type of data, then closed with a semicolon.

The addition of keywords var only needed once as long as there is no other keywords added.

The Program we have created has had a variable with the name of Form1 has the data type TForm1. If we see in the code editor, the complete listing is as follows (XE4):

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils,
  System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption:='Clicked';
end;

end.

TForm1 is data type that we make ourselves. But the creation is done automatically by Delphi in accordance with the arrangements we do.

Experiment of variables

On the first program that we make, the first time the program is executed, text that appear below the button is ‘Label1’. After the button is clicked, the text changed into ‘Clicked’. We will try to create a program with a different action. The first time the program is run, the text bellow the button is number zero. Every time button is clicked, the number bellow the button will go up.

Reopen the first Program, and then change the caption property of Button1 to ‘Up’ and caption of Label1 to ‘0’. Create a variable named Number with data type of integer. How to do this is by adding the line below Form1 declarations as follows:

var
   Form1: TForm1;  
   Number: integer;

After that, change the procedure TForm1.Button1Click to become as follows:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Number:=Number+1;
  Label1.Caption:=IntToStr(Number);
end;

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.
Please notice that comment or question submitted should match the topic. Otherwise, we will delete that comment or question :!:

3 Comments
  1. Terimakasih Ilmunya Pak Semoga bermanfaat

  2. type data int bukan 2 byte ya ?

    • Tipe data itu bisa berbeda-beda ukurannya tergantung kompilernya. Untuk Delphi, integer itu 4 byte. Tapi ingat, itu integer, bukan int.

Leave a comment

Before making a comment, make sure you have read the previous comments. Do not make the questions have been asked. Note also the links in the article. Take a look at those links before you create the questions, as it may be an explanation of your questions have been answered in that link.

Comments that do not follow these rules will be deleted!

(required)

(required)


Time limit is exhausted. Please reload the CAPTCHA.