Creating
Applications in Delphi 4
Brief
overview:
- Delphi is a fully object oriented programming tool that
uses Object Pascal programming language for Windows (use Delphi 1 for 16 bit Win3.x
applications and Kylix for Linux applications)
- It is not as easy as MS Access to create database
applications but once the initial learning curve has been
achieved, it has the tremendous advantage of vast
flexibility, speed and power in the type of applications
that one can create which are just not possible with MS
Access.
- You do not need to load MS Access each time you access a
database, just run your application!
- The files needed to deploy a delphi application on
another computer are:
- application exe file that you created
- an application help file if you created one
(Delphi does not create these, need other tools)
- if using a database, then the Borland Database
Engine files which need to be installed and
registered in Windows Registry
- any OCX ActiveX controls that you used
(preferably dont use them) - these also need to
be registered
- NB. Delphi comes with a version of Installshield
which can create floppy disk installations for
you easily.
- database access options:
- all versions:
- use the Borland Database Engine to access database
files, so that before one can access database files
(apart from Paradox and dBase which it can access without
an alias), one needs to create an alias to the database
in the BDE configuration program.
- Delphi 5 and higher (but not Kylix):
- Delphi 6, Kylix and higher:
- dbXpress - small DLL file that allows unidirectional queries to
databases via ODBC or JDBC
- As mentioned, Delphi can do almost anything that Windows
can do, which makes it an extremely complex tool, but
this complexity can be ignored for creating most
applications which are very simple to create.
Getting
started:
- use explorer to create:
- a new subdirectory of Delphi 4 projects directory
for each application you make
- a new subdirectory of Delphi 4 called LibMine
where you can store any shared units you make
- a shortcut to any application dpr file you create
so that it is easier to load each time you edit
the application
- a shortcut to any application exe file you create
so that it is easier to run the application
- use the Borland Database Engine configuration tool to
create aliases to any databases you wish to access.
- install any 3rd party components, highly recommended ones
are:
- Infopower (www.woll2woll.com)
- fantastic database access components
which makes it really easy to create:
- functional grids with automatic
record view dialogs, lookups,
embedded images, checkboxes, etc
- filter dialog boxes which allow
users to narrow down the records
seen
- locate dialog boxes which allow
users to locate a value in a
field
- incremental search control allows
users to enter values and locate
record as each value entered
- keycombo control allows users to
select an index which will the
change to sort order and also the
field that the incremental search
works on
- rich text editing controls
- Teechart Pro (www.teemach.com):
- this is an extension of the charting tool
used in Delphi4 which provides additional
functions:
- ReportBuilder Pro:
- Delphi comes with a reporting tool
"Quick Reports", but this is
another reporting tool with even greater
functionality and allows end-users to
create their own reports
- check out freebies and shareware components on
the internet:
- run Delphi 4 either via shortcut created above or from
start menu/programs/Delphi4
- by default, Delphi 4 starts up the project you pointed to
in shortcut, or if no shortcut used, a new project is
opened which by default is called Project1 and the unit
file is called Unit1. These should be renamed by
selecting File:SaveAs, remembering that the application
exe file name will be the same as the project name.
- you can change various options for the application by
selecting Project:Options. This allows you to set the
application title, icon, helpfile name (if you have made
one), which forms are automatically created, etc.
Basic components needed for a
Windows application:
- the Windows application:
- when you create a new application in Delphi, it automatically
creates for you, in addition to a blank form with its pascal unit
file, the following objects which are not immediately obvious to the
developer:
- the project source code file:
- Delphi adds the various units you use into this pascal file
and in its implementation section, places code to run your
application and create any forms that need to be created
automatically
- you can view this file by selecting View Source from the
menu
- the application object:
- this is in fact a form which is not seen as it has been
sized with width = 0 and height = 0, but keeps all the other
forms you create together at run time by managing the global
event loop and thus controls events such as onHint
- specify its title property so that users can see the name of
your application in the task bar
- specify a help file name so that when users click on help or
F1, the help file will be activated
- the screen object:
- this gives you access to the user's screen resolution, etc
as well as all the forms you have created
- the thread object:
- each Window application needs a thread to get access to the
CPU, as a developer you can ignore this object unless you wish
to create multiple threads to allow tasks to run in the
background or utilise multiple CPU's.
- the Form
(or "window"):
- this is already created for you by default. You
can create additional forms for use in the
application via File: New Form or File:New.
- consider setting the following properties for the
form:
- renaming the form by editing the name
property
- showhints = true (this allows hints to be
displayed when user leaves mouse over an
object)
- windowstate = wsMaximised (if you wish
form to be automatically maximised)
- windowpostition = poSreencenter (to centre
the form on the screen by default)
- forms can be MDI forms which means they
can contain child forms in a way that MS
Word does, where each document that is
opened is a child form which can be
minimised, if you create applications
like these, you need to create a menu
item called "Windows" which
allows user to select one of the open
child forms.
- to ensure automatic scaling of the form and its
components according to differing user screen resolutions:
- set Scaled property of forms to True
- use only True Type fonts (ie. don't use MS Sans
Serif)
- use Windows small fonts on the computer you use to
develop the forms
- set the Autoscroll property to false, if you want to
scale the form and not just the controls in it
- set the form position to either: upper-left corner
or windowpostition = poScreenCenter
- to ensure the user doesn't close the application
without saving data, write code in the main form's
OnCloseQuery event (not the OnClose event which may not
always be called)
- from the component palette which sits at the top of the
Delphi screen, you can select a component and add to form
by clicking on the form, the components that should be
considered are:
- menu
(on the "Standard" controls tab):
- double click on it to edit the menu then
either:
- right click and select insert
from template to insert ready
made menu items such as the usual
Windows "File",
"Edit",
"Help" menus, these can
then be edited as needed.
- type a caption in the blank
caption property:
- this will create a new
menu item
- if you enter a hyphen
alone, this will create a
separator bar on your
menu
- if you prefix any letter
with &, this will
create the underlined
keyboard accelerator key
- once a menu item has been created:
- you can create a keyboard
shortcut (eg. Ctrl-S or F4) to a
menu item by selecting one from
the shortcut property drop down
list
- you can add a hint that displays
when the user selects the item
via the hint property
- you can create a submenu by right
clicking on the item and
selecting "Submenu"
- you can drag and drop menu items
from one spot on the menu to
another
- if you double click a menu item
you can insert code to tell the
computer what to do when the user
clicks on this item (eg. for the
E&xit item, add code
"close;" which
instructs form to close, and if
the form is the main form, it
will also mean the application is
closed otherwise it will just
hide the form)
- many standard menu items are made easier to
implement by dropping a TActionList
component on the form and using this to allocate
an action for the menu item (eg. cut, paste, copy,
etc), others will need code attached to their
OnClick event.
- status bar:
- this has its align property set to
alBottom to force it to always be at the
bottom of the form
- select the panels property to add panels
to the bar and customise these
- select autoHint to display the hints from
the form objects in the 1st panel
- tool bar or top
panel for containing speed
buttons, etc:
- I tend to use a panel component as this
is easiest and set its caption to blank
and its align to alTop, to drop buttons
onto this just select the button
component from the pallette and click on
the panel - NOT the form.
- for win98 look, you can create dockable
tool bars, etc from the palette
- scrollbox
(if not an MDI form):
- I prefer to drop a scrollbox component in
the space between the top panel and the
status bar and set its align property to
alClient which means it will fill up all
the space available between those
components.
- This allows me to drop other components
onto the scrollbox such as database grids
and then when the user resizes the form
smaller, the user can access the entire
grid using the scrollbars.
-