Delphi Quickstart - A Transition From Java
Delphi Quickstart - A Transition From Java
Delphi has two environments, the text based environment, is known as a “console”
application called Pascal and a Graphical User Interface, (GUI) called Object Delphi. We
are studying Object Delphi.
The Object Delphi IDE comprises several tools, menus, commands, components and
properties that allow for the design and the execution of a program.
You will see these views at the bottom of the Delphi application screen.
The F12 button is used to switch between the Code view and the Design view.
You may also click in the respective sheets to gain access to these views.
Tool Palette
The Tool Palette is made up of items to help you develop an application. The items
displayed depend on the current view, that is, if you are currently viewing the design or the
source code of the application.
For example, if you are viewing a form in Design view, the Tool Palette displays controls
and components that are you can place onto the form.
If you for example select an item from the tool palette, it will allow you to select a
component listed in this item.
the component in the tool palette and the IDE will locate it for you.
Example: I searched for a component called RichEdit in the tool palette, it showed two
results, one from Win32 and the other from Data Controls.
If you are viewing code in the Code Editor, the Tool Palette displays code segments that
you can add to your application.
This allows you to customize the properties of and to create event handlers for the
components in the application created. Each form and each object has a set of properties
such as colour, font, size, position, caption etc that can be modified in the Delphi IDE or in
your code. Each component also has a collection of events such as a mouse click or
component activation for which you can specify the behaviour of the component during run
time. The Object Inspector has two tabs (Properties and Events) that displays the
properties and events for the selected object (component) and allows you to change the
property value or select the response to some event.
When a new project is created in Delphi, the following files must be saved.
Notice that the Pascal file is made up of the interface and the implementation section.
Interface:
Consists of the uses section that lists the different pre-defined units (classes) used.
A type declaration that specifies the form name/s, private and public declarations.
A var declaration for declaring global constants, variables, procedures and functions.
Implementation
Label Standard
Button Standard
Spinner Samples
Slider Win32
Table Additional
Naming Components
Ideally, three letters should be prefixed to a component name.
Prefix of components
Component Prefix
TLabel lbl
TButton btn
TPanel pnl
TGroupBox grp
TEdit edt
TRichEdit red
TCombobox cmb
TListBox lst
TCheckbox chk
TRadioGroup rgp
TRadioButton rbt
TSpinEdit spn
TTrackBar trk
TStringGrid sgd
DATA TYPES
Netbeans Delphi
int integer
double real / single / double
boolean boolean
char char
string string
The real data type is widely used and is recommended rather than single and double.
Variables
be reserved words.
start with a number.
have whitespaces or hyphens for separation.
Global variables are created in the main form under the interface part of the class, and
can be accessed throughout the form / class.
Notice that the variables names is also an indication of the data type it contains.
Note all changes to the components on the form will take place in the Object Inspector.
The properties in the Object Inspector are in alphabetical order.
Go to File Save As
Browse to the Delphi Projects folder that you created Open the Tutorial1 folder
Once the project is saved properly, you can design the application. Click on the
save icon to update and to save changes to the form as you progress.
Note: It is not compulsory to follow this sequence when saving a project; it is also
possible to save to the folder at any time using the same steps.
1. Form
Make use of the new VCL form created. Change the caption to Components and
the name to frmComponents. To do this, go to the Object Inspector and change the
following properties:
3. Label
Place a TLabel from Standard components onto the group box grpInput.
Go to Object Inspector, change the following properties.
Place another TLabel for surname onto the group box grpInput.
Place another TLabel for height onto the group box grpInput.
Compiled by Georgina Ramsamy
Property Explanation Object Inspector
Caption to Height Label3 will now read Height
Name to lblHeight Use this name if required in coding
Font to Ariel The appearance of the label on the
Size to 11 form will change accordingly
Colour to Black
Place another TLabel for age onto the group box grpInput.
4. Text Box
Place a TEdit from Standard components onto the group box grpInput.
Go to Object Inspector, change the following properties.
Place another TEdit for surname onto the group box grpInput.
Change the following properties.
Place another TEdit for height onto the group box grpInput.
Change the following properties.
5. Spinner
6. Combo box
Place a TComboBox from Standard components onto the group box grpInput..
Go to Object Inspector, change the following properties.
Place a TRadioGroup from Standard components onto the group box grpInput.
Go to Object Inspector, change the following properties.
8. List box
Place a TListbox from Standard components onto the group box grpInput.
Go to Object Inspector, change the following properties.
Place a TCheckbox from Standard components onto the group box grpInput.
Go to Object Inspector, change the following properties.
11. Button
Place a TRichEdit from Win32 onto the group box grpOutput. Go to Object Inspector,
change the following properties.
A TBitButton has all the features of a button and also has the ability to add a glyph. A
glyph is also known as a special symbol or icon.
The TBitButton is generally used for a specific purpose. Examples are as follows:
TBitButton Symbol
Abort
All
Cancel
Close
Help
Ignore
No
Yes
OK
Retry
After placing the TbitButton on the Form, select the “Kind” property from the Object
Inspector to customise the type of button you require.
Note that the “Close” BitButton was used in the GUI given.
Escape Sequences
Symbol Function
#9 Used to leave a Tab space depending on the Tabcount created
#13 Used as a line feed to move onto a new line
We are now ready to code the “Extract and display” button in the GUI.
Note the word “var” is used to indicate the variables used for this button.
Code to extract the information from the components and to display in the output area.
Press F9 OR select the icon in the Tool bar OR select the “Run” option from the
Menu Bar.
In order to align the information of the TRichEdit componenent, a tab count must be
created.
Step 2: Specify the value of the column where each Tab should start.
Step 3: The #9 must be used to move from one Tab stop to the other.
redOutput.Paragraph.TabCount := 2;
Step 2: Specify the column value where each Tab should start.
redOutput.Paragraph.Tab[0] := 10;
redOutput.Paragraph.Tab[1] := 100;
Step 3: The #9 must be used to move from one Tab stop to the other.
The display part of the program segment will now change to:
Example:
rNumber1:= 713.6795678;
Notes:
FloatToStrF This function is used to convert a real number to a string with formatting
rNumber1 The variable name of the value to be converted
ffFixed Used when rounding off to a specific number of decimal places
5 The maximum number of digits the integer part of the number can contain
2 The number of digits after the decimal point
Formatting to currency
Example:
rPrice := 927.89;
FloatToStrF This function is used to convert a real number to a string with formatting
rPrice The variable name of the value to be converted
ffCurrency Used to specify the currency and to round off to a specific number of
decimal places. The currency displayed will depend on the system
settings.
5 The maximum number of digits the integer part of the number can contain
2 The number of digits after the decimal point