Quick Start: Delphi 4
Quick Start: Delphi 4
Borland ®
™
Delphi 4
for Windows 95 and Windows NT
Inprise Corporation, 100 Enterprise Way
Scotts Valley, CA 95066-3249
Refer to the file DEPLOY.TXT located in the root directory of your Delphi 4 product for a complete list of files that you
can distribute in accordance with the No-Nonsense License Statement.
Inprise may have patents and/or pending patent applications covering subject matter in this document. The
furnishing of this document does not give you any license to these patents.
COPYRIGHT © 1998 Inprise Corporation. All rights reserved. All Inprise and Borland products are trademarks or
registered trademarks of Inprise Corporation. Other brand and product names are trademarks or registered
trademarks of their respective holders.
Printed in the U.S.A.
HDA1340WW21000 1E0R598
9899000102-9 8 7 6 5 4 3 2 1
D4
Contents
Chapter 1 Chapter 4
Introduction 1-1 Customizing the environment 4-1
What is Delphi? . . . . . . . . . . . . . . . . . . 1-1 Organizing your work area . . . . . . . . . . . . 4-1
Where to find information . . . . . . . . . . . . 1-1 Organizing tools . . . . . . . . . . . . . . . . . 4-2
Online Help . . . . . . . . . . . . . . . . . . . 1-2 Organizing menus and toolbars . . . . . . . . 4-4
Printed documentation . . . . . . . . . . . . 1-4 Setting project options . . . . . . . . . . . . . . . 4-5
Inprise developer support services . . . . . . 1-4 Setting options for all new projects . . . . . . 4-6
Inprise Web site. . . . . . . . . . . . . . . . . 1-4 Restoring Delphi’s original default
Manual conventions . . . . . . . . . . . . . . . . 1-4 settings . . . . . . . . . . . . . . . . . . . . . 4-6
Creating project defaults . . . . . . . . . . . . . . 4-6
Chapter 2 Specifying a default project . . . . . . . . . . 4-6
A tour of the environment 2-1 Displaying a default form . . . . . . . . . . . 4-7
Starting Delphi . . . . . . . . . . . . . . . . . . . 2-1 Setting tool preferences. . . . . . . . . . . . . . . 4-7
Placing components on a form . . . . . . . . . . 2-2 Customizing the Code editor . . . . . . . . . 4-8
Changing component appearance and Customizing the Component palette . . . . . . . 4-8
behavior . . . . . . . . . . . . . . . . . . . . . . 2-3 Rearranging the Component palette . . . . . 4-9
Navigating among events . . . . . . . . . . . 2-4 Adding components to Delphi. . . . . . . . 4-10
Editing code . . . . . . . . . . . . . . . . . . . . 2-4 Installing component packages . . . . . 4-10
Browsing with the editor . . . . . . . . . . . 2-5 Adding ActiveX controls . . . . . . . . . 4-10
Navigating within your project . . . . . . . . 2-5 Creating component templates . . . . . . . 4-11
Navigating within your code . . . . . . . . . 2-6 Customizing Delphi Help . . . . . . . . . . . . 4-11
Getting help while coding . . . . . . . . . . . 2-7
Organizing the environment . . . . . . . . . . . 2-8 Chapter 5
Debugging applications . . . . . . . . . . . . . . 2-9 Programming with Delphi 5-1
Exploring databases . . . . . . . . . . . . . . . . 2-11 Delphi development environment . . . . . . . . 5-1
Storing objects as templates. . . . . . . . . . . . 2-11 Designing applications . . . . . . . . . . . . . . . 5-2
Project management tool . . . . . . . . . . . . . 2-13 Using the VCL . . . . . . . . . . . . . . . . . . 5-2
Handy pop-up menus . . . . . . . . . . . . . . . 2-14 Creating the application user interface . . . . 5-4
Toolbars . . . . . . . . . . . . . . . . . . . . . . . 2-14 Using components . . . . . . . . . . . . . . . 5-4
Getting help . . . . . . . . . . . . . . . . . . . . 2-15 Changing component behavior . . . . . . . . 5-5
Designing menus . . . . . . . . . . . . . . . . 5-5
Chapter 3 Developing applications . . . . . . . . . . . . . . 5-6
Your first application–a brief Creating Windows GUI applications . . . . . 5-6
Creating packages and DLLs. . . . . . . . . . 5-7
tutorial 3-1 Handling exceptions . . . . . . . . . . . . . . 5-7
Starting a new application . . . . . . . . . . . . 3-1
Writing database applications . . . . . . . . . . . 5-8
Setting property values . . . . . . . . . . . . . . 3-3
Connecting to databases . . . . . . . . . . . . 5-8
Adding objects to the form . . . . . . . . . . . . 3-3
Using database tools . . . . . . . . . . . . . . 5-8
Accessing a database . . . . . . . . . . . . . . . 3-5
Browsing databases . . . . . . . . . . . . . 5-9
Adding support for a toolbar and a menu . . . 3-7
Storing data information . . . . . . . . . . 5-9
Adding a menu. . . . . . . . . . . . . . . . . . . 3-8
Editing existing database tables . . . . . . 5-9
Adding a toolbar . . . . . . . . . . . . . . . . . . 3-10
Configuring databases . . . . . . . . . . 5-10
Displaying an image. . . . . . . . . . . . . . . . 3-11
Understanding database application architecture
Final touches . . . . . . . . . . . . . . . . . . . . 3-12
5-10
Hooking up an event handler . . . . . . . . . . 3-13
i
Developing distributed applications. . . . . . . 5-11 Using MTS with Delphi. . . . . . . . . . . . 5-13
Developing CORBA applications. . . . . . . 5-12 Creating and editing type libraries . . . . . 5-14
Developing distributed applications Deploying applications. . . . . . . . . . . . . . 5-14
using COM and MTS. . . . . . . . . . . . . 5-12 Building custom components . . . . . . . . . . 5-15
Creating COM applications with
wizards . . . . . . . . . . . . . . . . . . . . 5-13 Index I-1
Tables
1.1 Online Help documentation . . . . . . . . 1-2 4.1 Project options . . . . . . . . . . . . . . . . 4-5
1.2 Typefaces . . . . . . . . . . . . . . . . . . . 1-4 5.1 Delphi product versions . . . . . . . . . . . 5-2
2.1 Code Insight tools . . . . . . . . . . . . . . 2-7
ii
Chapter
1
Introduction
Chapter 1
What is Delphi?
Delphi is an object-oriented, visual programming environment for rapid application
development (RAD). You can use it for developing all kinds of applications from
general-purpose utilities to sophisticated data access programs, including client/
server applications. Using Delphi, you can create highly efficient Microsoft
Windows 95, Windows 98, and Windows NT applications with a minimum of
manual coding.
Delphi provides a comprehensive library of reusable components and a suite of RAD
design tools, including application and form templates, and programming wizards.
These tools simplify application prototyping and development and shorten
development time.
When you start Delphi, you are immediately placed within the visual programming
environment. It is within this environment that Delphi provides all the tools you
need to design, develop, test, and debug applications.
Introduction 1-1
Where to find information
Refer to What’s New in Delphi? in online Help and the Inprise Web site for information
about new features for this release.
Online Help
You can use online Help to get detailed information about using Delphi while using
the product. Referring to Help is a convenient way to learn about the extensive
language features, programming tasks, compiler options, and other development
tools.
Delphi provides detailed online reference information for numerous reusable
components such as the Visual Component Library and Win32 APIs. Online
reference is the fastest way to get information on language syntax and component
properties, methods, and events as you are developing applications.
Delphi includes the following Help files:
You will also find Help on additional products that are supplied with some versions
of Delphi, such as the following:
• Borland Database Engine Help
• Borland Database Engine Administrator Help
• Database Explorer Help
• PVCS Version Manager Help
• Local SQL Help
• SQL Builder Help
• WinSight User’s Guide Image Editor Help
• Win32 Help files
• Help Author’s Guide (Help Workshop)
• NEWT Intranet ActiveX Help
• QuickReport Help
• TeeChart Help
• InterBase Help
• Help for miscellaneous components (FastNet Time, DayTime, Echo, Finger, HTTP,
NNTP, POP3, Powersock, SMTP, UDP, URL Encode/Decode, UUprocessor,
Stream and Msg components)
The Help files are located in the Help directory under the main Delphi directory.
Introduction 1-3
Manual conventions
Printed documentation
This Quick Start is meant to get you started with using Delphi. For information about
ordering additional printed documentation, refer to the Inprise Web site at
www.inprise.com.
Manual conventions
This manual uses the typefaces described in Table 1.2 to indicate special text.
Palette of ready-
made components
to use in your
application.
A blank form on
which to start
designing the UI for
your application.
An application can
include many
forms.
Or, choose a
component from an
alphabetical list.
Select a property
and change its
value in the right
column.
Many of the properties have standard values, such as colors, True or False, or
positions. For properties that have binary values like True or False, you can click on
the word to change the value to its opposite. Other properties have associated
property editors to set more complicated sets of properties. When you click on a
property value, you’ll see an ellipsis.
Double-click here to
change the value from
True to False.
Editing code
As you visually design the user interface for your application, Delphi generates the
underlying Pascal code. When you select and modify the properties of forms and
components, the results of those changes are automatically reflected in the project or
the form file.
You can also add code to the source files directly using the built-in Code editor.
Notice that
components added to
the form are reflected
in the code.
Delphi-
generated
code.
The Delphi Code editor is a full-featured ASCII editor. If using the visual
programming environment, a form is automatically displayed as part of a new
project. The contents of the form, all its properties, and its components and their
properties can be viewed and edited as text in the Code editor by selecting the View
as Text option in the form designer’s context menu.
The Delphi code generation and property streaming systems are completely open to
inspection. The source code for everything that is included in your final EXE—all of
the VCL objects, RTL sources, all of the Delphi project files can be viewed and edited
in the Code editor.
Within the Code editor, you can also move between the declaration of a procedure to
its implementation and back again. Type Ctrl+Shift+↑ (or Ctrl+Shift+↓).
Code Insight includes several features that you configure from the Environment
Options dialog box. Select Tools|Environment Options and select the Code Insight
page. These options are on by default when you install Delphi. Code Insight tools are
described in Table 2.1.
You can also dock two or more windows next to each other to maintain fast one-step
access to the tools.
Debugging applications
Delphi provides an integrated debugger that helps you locate and fix errors in your
applications and dynamic link libraries (DLLs). The integrated debugger lets you
control program execution, monitor variable values and items in data structures, and
modify data values while debugging.
Choose Tools|Debugger
Options and set debugging
options on all four pages.
Run button
Debugger buttons
Choose Project|
Options, select the
Compiler page and
check Debug
Information
After you compile your program with debug information, you can begin a
debugging session by running your program from the IDE. Many debugging views
are available to you including a Breakpoint List, Call Stack, Watch List, Local
Variables, Thread Status, Modules, CPU view, and an event log. Display them by
choosing View|Debug Windows.
You can view the values of variables, functions on the call stack, and program output
to check that the area of code you are examining is performing as designed. You can
also step through your code line by line examining the state of the program, viewing
the program output, and modifying program data values.
Lots of information is available to
you while debugging. Choose View|
Debug Windows and select the ones
you want.
You can dock many of the
debugging views together overlaying
each other. Click the tabs to see the
different views.
Exploring databases
The SQL Explorer (or Database Explorer in the Standard and Professional editions of
Delphi) lets you work directly with a remote database server during application
development. For example, you can create, delete, or restructure tables, or import
constraints while you are developing a database application.
Choose Database|
Explore to display the
Explorer. You can see
and change the data in a
table.
And you can query a
database directly.
You can use the Tools|Repository command to add objects to the Object Repository.
Those objects are then available using the File|New command, which opens the New
Items dialog box:
Delphi includes a
centralized repository
for storing and
reusing data models,
business rules,
objects, and forms.
Many of the pages
include wizards that
simplify development
of that type of
application or object.
You can also access the many objects and wizards that Delphi provides on the tabbed
pages. The number and type of objects available to you is dependent on the version
of Delphi that you purchased.
The Project Manager shows you a high-level view of the projects contained in a
project group, and of the form, unit files, resource, object, and library files contained
in the project file. You can use the Project Manager to open, add, save, and remove
project files. You can also use the Project Manager to access default project settings.
The Project Manager is a useful tool if you share files among different projects
because it lets you quickly find each file in the project. It can also be used for other
common project management tasks such as package management and resource (.RC)
management.
Toolbars
The Delphi toolbars, located in the main window, contain buttons that provide quick
access to common operations and commands (Open, Save, Run, and so on).
Standard toolbar View toolbar
Remove
Open file from
New Save project View Toggle
project Cut Paste
units form/unit
Getting help
Delphi’s online Help provides extensive documentation on Delphi.
Here are some of the many ways you can display help:
Press F1 on a property or
event name in the Object
Inspector to display help.
Press F1 on a property,
event, method, function,
procedure, or type in the
Code editor to display help.
You can display help on any part of the development environment including menu
items, dialog boxes, windows, screens, toolbars, and components.
3 Choose File|Save All to save your files to disk. When the Save dialog appears,
navigate to your MySource folder, and save the Delphi files using their default file
names. (You can also use the Delphi Save As dialog box to create the new
MySource directory.)
In addition to the files already mentioned, Delphi creates other files associated
with your project, as you can see by looking in your MySource directory.
In Delphi, you design the user interface for your applications using forms. Forms can
contain menus and context menus, they can be put together to make application
dialog boxes, and they can be parent or child windows. Essentially, forms are the
canvases on which you create applications.
When you open a new project, Delphi displays a graphical representation of the
project form, named Form1 by default.
You place objects on forms to create user interfaces. Objects, for example, can be
standard interface controls (such as check boxes and drop-down lists), or they can be
full-featured components (such as data grids, bar charts, and editors).
In addition to the form, Delphi also displays the Object Inspector. With the Object
Inspector, you can set values for the objects you’ve placed on your forms.
Figure 3.1 Objector Inspector
Add components to the interface by selecting the You can also double-click a component to put
component on the palette then clicking on the form the component in the middle of the form.
where you want to place it.
Using the components on the Component palette, Delphi enables you to quickly
create an interface for your application.
1 Drop a Table object onto the form.
Click the Data Access tab on the Component palette. To find the Table component,
point at a component in the Component palette for a moment; Delphi displays a
Help hint showing the name of the component, as shown here.
When you find the Table component, click it once to select it then click on the form
to drop the component onto the form. Delphi adds that component to the middle
of the current form. (The Table component is nonvisual so it doesn’t matter where
you put it.) Delphi names the object Table1 by default.
Note Placing a component on a form creates an object instance of that component. Once
the component is on the form, Delphi generates all the Object Pascal code
necessary to create that object in your application. Here is the great advantage of
using Delphi: you don’t have to worry about the code that creates or maintains the
objects you use in your application—Delphi does all that work for you.
2 Set the DatabaseName property of the table to DBDEMOS. (DBDEMOS is the alias
to a database that contains the table you’re going to use.) You can select
DBDEMOS from DatabaseName property drop-down list.
4 Set the AutoHint property of the status bar to True. The easiest way to do this is to
point and double-click on False next to AutoHint. (This will cause help hints to
display later when you point to a tool on a toolbar.)
Accessing a database
You’re now ready to connect database controls to the database, your data source.
1 Any time, you can enlarge the size of you application’s window by dragging the
lower right corner of the form.
2 From the Data Access page of the Component palette, drop a DataSource
component on the form. The DataSource component is nonvisual so it doesn’t
matter where you put it on the form. Set its DataSet property to Table1.
3 From the Data Controls page, choose the DBGrid component and drop it onto your
form. Position it in the lower left corner of the form above the status bar and
expand it. Your form should now resemble the following figure.
5 Set the DataSource property of DBGrid to DataSource1 to access the database you
set up with the Table and DataSource objects.
Now you can finish setting up the Table1 object you previously dropped on the
form.
6 Give the Table1 object focus by clicking on it in the form, then set its properties as
follows:
• Set TableName to BIOLIFE.DB (Name is still Table1).
• Set Active to True.
When you set the Active property to True, the grid fills with the data contained in
the BIOLIFE.DB database table. (If the grid doesn’t fill as shown in the following
figure, make sure you’ve correctly set the properties for all of the application
objects as explained in the previous instructions.)
Since the DBGrid control is data aware, it displays the data in the table while you
are designing your application. The data display gives you a visual check,
showing that you’ve correctly hooked up to the database. However, note that
being data aware doesn’t mean you can edit the data at design time. To edit the
data in the table, you’ll have to run the application.
7 Press F9 to compile and run the project.
6 Right-click on the Action List designer and choose New Standard Action. The
Standard Actions list box is displayed.
Adding a menu
In this section, you’re going to add a menu with three top-level items (File, Edit, and
Record). You’ll add menu items to each using some of the standard actions you
added to the action list.
1 From the Standard page of the Component palette, drop a MainMenu component
onto the form. It’s nonvisual at this point so anywhere is OK.
2 Set its Images property to ImageList1.
3 Double-click the menu component to display the Menu Designer.
4 Type &File to set the Caption property of the first top-level menu item and press
Enter.
5 Type &Save and press Enter to create a Save menu item under File.
6 Type a hyphen in the next item under the File menu and press Enter to create a
separator bar on the menu.
7 Type E&xit and press Enter to create an Exit menu item under File.
8 Click on the second top-level menu item (to the right of File) and type &Edit and
press Enter. The menu item under Edit is selected.
• In the Object Inspector, set its Action to Cut1 and press Enter.
• Select the next menu item under Cut, set its Action to Copy1 and press Enter.
• Select the next menu item under Copy, set its Action to Paste1 and press Enter.
9 Click on the third top-level menu item (to the right of Edit) and type &Record and
press Enter. The menu item under Record is selected.
• In the Object Inspector, set its Action to First1 and press Enter.
• Select the next menu item under First, set its Action to Prior1.
• Select the next menu item under Prior, set its Action to Next1.
• Select the next menu item under Next, set its Action to Last1r.
10 Click on the X to close the Menu Designer.
You can then press F9 to compile and run the program to see how it looks:
Adding a toolbar
1 On the Win32 page of the Component palette, double-click the toolbar to add it to
the form.
• Set the Indent property to 4.
• Set the Images property to ImageList1.
• Set ShowHint to True.
2 Add buttons to the toolbar:
• With the toolbar selected, right-click and choose New Button three times.
• Right-click and choose New Separator.
• Right-click and choose New Button four more times.
3 Assign actions to the first set of buttons:
• Select the first button and set its Action to Cut1.
• Select the second button and set its Action to Copy1.
• Select the third button and set its Action to Paste1.
4 Assign actions to the second set of buttons:
• Select the first button and set its Action to First1.
• Select the second button and set its Action to Prior1.
• Select the third button and set its Action to Next1.
• Select the last button and set its Action to Last1.
Here’s how it looks:
Displaying an image
Now you can associate a picture with each record in the table.
1 From the Standard page of the Component palette, drop a Panel component onto
the top of the form below the toolbar. Delphi names this Panel1 by default. To
remove this caption from your running application, clear the Panel1 string from
the panel’s Caption property.
2 Align Panel1 to the top of the form by setting its Align property to alTop. Next drag
the bottom of the panel down so it fills the top portion of the form.
6 Click the Run button (the arrow) on Delphi’s toolbar to compile and run your
application.
Final touches
Now when you run the application, you can easily move through your database table
using the buttons on the toolbar. You can add a couple of other touches to complete
the application. Close the running application to return to the design mode of Delphi.
1 Select Panel1.
2 From the Data Controls page of the Component palette, drop a DBMemo
component onto Panel1 and position it so it occupies the upper left corner of the
panel (below the menus and toolbar). Next, set the following property values:
• Set DataSource to DataSource1.
• Set DataField to Notes (use the drop-down list of fields).
• Set ScrollBars to ssVertical.
3 Drop a DBText object on Panel1 under the DBMemo object. Enlarge the DBText
object so it fills the area under the DBMemo, then set its properties as follows:
• Set DataSource to DataSource1.
• Set DataField to Common_Name.
• Set Alignment to taCenter.
4 Customize the Font property of the DBText object using the Font editor.
You can access several different types of property editors through the Object
Inspector. For example, you can use the Menu editor, the Font editor, and the
Picture editor to edit form menus, label fonts, and bitmap pictures and glyphs,
respectively.
When you click the Font property of the DBText object, Delphi displays an ellipsis
button on the right side of the property setting, indicating that you can use a
property editor to set this property. Clicking anywhere on the property value
displays the Font editor, a dialog box that lets you edit several characteristics of
fonts.
Modify the following DBText settings using the Font editor, then click OK when
you’re done:
• Set the Font Style to Bold.
• Set the Color to Silver.
• Set the Size to 12.
5 You can adjust the form so it looks the way you want it. Then, compile and run
your application by pressing F9.
You now have a fully functioning Windows application that accesses a database table
and displays images, text, and individual data fields from the database. There’s even
a toolbar and a menu with active commands on them.
initialization work and save your coding efforts for the event handlers, the code that
makes your program perform the tasks in your application.
Your next programming feat will be to hook up an event handler to a menu item, a
task you’ll encounter often when designing user interfaces with Delphi. You’ll
program the command so that when clicked, an event handler will call the standard
Windows File|Save dialog box, which lets you save information from the database
into a file.
1 From the Dialogs page of the Component palette, drop a SaveDialog object onto the
form.
Now comes the most important part of your Delphi programming: creating and
writing an event handler. The easy part is creating the event handler; technical
programming comes into play as you write the Pascal code for the event.
2 Choose File|Save from your form to create the default event handler for the
button.
3 Whenever you select a menu item or double-click an object on a Delphi form,
Delphi generates the code for that object’s default event handler. The Code editor
opens with the cursor placed within the skeleton code for the event handler:
Up until now, you’ve used the Object Inspector to set object properties. You can
also use the Object Inspector to access and create object event handlers. By clicking
the Events tab on the Object Inspector, you can see the available events for the
object currently in focus on the Delphi form.
Most components on the Component palette have a default event. When you
double-click an object on a form, Delphi creates the handler for the default event.
For most components, the OnClick event is default; this is the event that gets called
whenever you click an object in a running application.
4 Complete the event handler by adding the code that is shown in the var section
and between the begin and end of the event handler:
Detailing the workings of this code is beyond the scope of this tutorial. What the
code does is call the File Save dialog box (the SaveDialog1 object) when you choose
the File|Save. When you specify a file name, your application writes data on the
currently selected fish to a text file.
5 To add code for the Exit command, choose File|Exit. Delphi generates and
displays the skeleton event handler in the editor:
procedure TForm1.Exit1Click(Sender: TObject);
begin
end;
Right where the cursor is positioned (between begin and end), type
close;
6 To run the application, press F9.
Congratulations! You have now completed a working Delphi application.
To save the new program to disk, choose File|Save Project As. You can exit the
program using the newly activated File|Exit command.
Organizing tools
Delphi lets you organize all of the tools and tool windows as you want to on the
desktop. The windows and tools are all separate and can be displayed or closed,
however you like to work. Many of the windows can be docked (attached) to other
windows and some of the windows can be docked on top of other windows forming
tabbed tool windows.
For example, while you’re designing the application interface, you might want to
dock the Project Manager and the Code Explorer onto the Code editor.
You can dock windows onto others. Here the Project Manager
and the Code Explorer are docked onto the Code editor.
While debugging code, you can dock watch and breakpoint views onto the editor.
From these views, you can click on a breakpoint or watch and go right to that
location in the code.
There are infinite ways to organize Delphi tools. As you’re working, you’ll have to
experiment to discover the most convenient way for you to work.
Main window
showing the
default
organization.
You can move the parts around within the main window. Click the grabber (the double bar on the left
of the menu or toolbars) and drag it to where you want it.
Main window
organized differently.
You can pull these parts off the main window organizing them any way you want or
removing them from the desktop altogether.
You can break up the parts of the main window. Click the grabber (the double bar on the left of the
menu or toolbars) and drag it to where you want it.
Further, you can customize all the toolbars adding or deleting available tools.
Right-click on any
toolbar and choose
Customize.
From the Commands
page, you can select
any command listed
and drag it onto the
toolbar.
You can also designate a project wizard to run by default when you start a new
project. A project wizard is a program that enables you to build a project based on
your responses to a series of dialog boxes.
You always have the option to override the defaults by choosing File|New and
selecting any item from any of the tabbed pages available through the New Items
dialog box.
Set your own colors for the editor including syntax highlighting on
the Colors page. Set font and other properties on the Display page.
• Create component templates (standard or custom) and add them to the palette
Delphi provides a default Help system that includes all the Help files in the master
table of contents. Choosing Help|Contents in Delphi displays this table of contents.
With OpenHelp, you can customize the Help system so it displays the information
you want it to. You can add or remove Help files. You can even add Help for
additional tools you work with in the Delphi development environment. OpenHelp
also allows you to remove references to obsolete Help files from the system registry.
OpenHelp stores information about your Help system in a project. The project
defines a master table of contents, master index, and a context-sensitive Help search
range for a set of Windows Help files.
Another way to find out about the IDE is to select any window, tool, or dialog box
and press F1. You can also use the online tutorials provided with Delphi.
Designing applications
You can use Delphi to design any kind of 32-bit application—from general-purpose
utilities to sophisticated data access programs. Delphi’s database tools and data-
aware components let you quickly develop powerful desktop database and client/
server applications. Using Delphi’s data-aware controls, you can view live data while
you design your application and immediately see the results of database queries and
changes to the application interface.
The type of application you can design is somewhat determined by the specific
Delphi product version you purchased. Different product versions support different
types of program development. Table 5.1 describes the main features of each version.
TGraphicControl TWinControl
TScrollingWinControl TCustomControl
You can learn about the available objects in the hierarchy by browsing through the
VCL Reference online, or by glancing at the VCL poster included with the product.
The VCL is intimately tied to the Delphi IDE, and is what gives you the ability to
quickly develop applications. Components are the elements you use to build your
Delphi applications. They include all the visible parts of an application interface,
such as dialog boxes and buttons, as well as those that aren’t visible while the
application is running, such as system timers or COM servers.
All VCL objects, and in fact all objects in Object Pascal, are derived from TObject.
TObject is unique in that it is an abstract object that has no properties or events, only
methods that allow you to derive objects from this base class. Use TObject as the
immediate base class when writing simple objects that are not components.
Components are objects that you can manipulate at design time. All components in
the VCL are derived from the abstract component type TComponent. TComponent
provides the minimal properties and events necessary for a component to work in
Delphi (for example, so the component can be installed on the Component palette
and added to forms visually by dropping it). The various branches of the library
provide other, more specialized capabilities.
The VCL components you will likely use the most are the VCL’s controls, such as
TForm or TSpeedButton. Controls are visual components derived from the abstract
component type TControl.
Of the over 600 objects in the VCL, most are not visual. The Delphi IDE allows you to
visually add some nonvisual components to your programs. For example, to write a
database application that connects to a table, you could drop a TDataSource
component on your form. TDataSource is a nonvisual component, but is represented
on the form by an icon (which doesn’t show up at runtime), and you can manipulate
the properties and events of TDataSource in the Object Inspector just as you would a
visual control.
Using components
Many of the VCL components are provided in the development environment itself
on the Component palette. You select components from the Component palette and
drop them onto the form to design the application user interface. Once a visual
component is on the form, you can adjust its position, size, and other design-time
properties using the Object Inspector without having to write a single line of code.
Delphi components are grouped functionally on the different pages of the
Component palette. For example, commonly used components such as those to
create menus, edit boxes, or buttons are located on the Standard page of the
Component palette. Handy controls such as a timer, paintbox, and media player are
on the System page.
Components achieve a high degree of encapsulation. For example, consider the use
of a dialog containing a push button. In Delphi, the push button component is pre-
programmed to respond to a mouse click using its built-in OnClick event handler.
Your program does not have to determine that a button has been clicked. You only
provide the routine that is called when the button is clicked, and through the Object
Inspector, assign that routine to the OnClick event of the button.
Similarly, most Windows messages are handled by Delphi components. When you
want to respond to a Windows message, you need only provide an event handler.
Designing menus
After you add a menu component to a form, you can use the Menu Designer to create
and edit menu bars and pop-up menus. You need to add a menu component to your
form for every menu you want to include in your application. Delphi provides
predesigned menu templates that you can use to design menus, or you can build the
menu structure of your program from scratch.
The menus you design are immediately visible in the form without having to run the
application to see the results. You can also change menus at runtime to provide
additional options for the application user.
Developing applications
One of Delphi’s strengths is that it simplifies Windows application development.
Delphi includes several wizards and other specialized tools that speed up the
development process. Delphi is an ideal tool for developing all types of business
applications, games, custom controls, utilities, Web-enabled applications, and
complex database applications.
Following are the three basic types of Windows applications you can use Delphi to
develop:
• Windows GUI applications
• Console applications
• Service applications
Windows GUI applications are the most common type of software available for the
Windows platform. The Graphical User Interface (GUI) consists of windows and
dialog boxes which work together to perform a group of functions. Word processors,
spreadsheets, and Delphi are examples of GUI applications. Delphi is also well-
suited for developing console applications (such as Grep) and service applications
(such as NT servers).
You can develop dynamic link libraries (DLLs) and packages, a special type of DLLs,
to add features to the design environment or to the application itself. See “Creating
packages and DLLs” on page 5-7.
You can also use Delphi to develop other specialized types of applications. Refer to
“Writing database applications” on page 5-8 for information about some of the tools
available to help with database application development. See “Developing
distributed applications” on page 5-11 for information on client/server applications.
Handling exceptions
Error conditions in Delphi are indicated by exceptions. An exception is an object that
contains information about what error occurred and where it happened. Exceptions
are built into many classes and they are raised automatically when something
unexpected occurs. You need to use exception handling to recognize, locate, and deal
with programming errors.
Delphi includes many exception classes for automatically handling errors such as
divide-by-zero and file input/output errors. All of the exception classes descend
from one root object called Exception. Exception encapsulates the fundamental
properties and methods for all exceptions and provides a consistent interface for
applications to handle exceptions.
Connecting to databases
The BDE includes drivers to connect to different databases. The Standard version of
Delphi includes drivers for local databases: Paradox, dBase, FoxPro, and Access.
With the Professional version, you also get access to Open DataBase Connectivity
(ODBC). The goal of ODBC is to make it possible to access any data from any
application, regardless of which database management system is handling the data.
An ODBC adapter allows the BDE to use vendor-supplied ODBC drivers. By using
the ODBC driver, your application can access any ODBC-compliant database.
The Client/Server and Enterprise versions include drivers for remote database
servers. You can use the drivers installed with SQL Links to communicate with
remote database servers such as Interbase, Oracle, Sybase, Informix, Microsoft SQL
server, and DB2.
Browsing databases
SQL Explorer in Delphi Client/Server and Enterprise (or Database Explorer in the
other editions) is a hierarchical browser for inspecting and modifying database
server-specific schema objects including tables, fields, stored procedure definitions,
triggers, references, and index descriptions.
Through a persistent connection to a database, the explorer lets you
• Create and maintain database aliases
• View schema data in a database, such as tables, stored procedures, and triggers
• View table objects, such as fields and indexes
• Create, view, and modify data in tables
• Enter SQL statements to directly query any database
• Create and maintain data dictionaries to store attribute sets
Configuring databases
The BDE Administrator is included with Delphi. You use the BDE Administrator to
perform tasks such as the following:
• Configure the BDE
• Configure standard (Paradox, dBASE, FoxPro, and ASCII text), SQL, Access, and
ODBC drivers; create and delete ODBC drivers
• Create and maintain database aliases
Choose File|New and look at the Multi-tier page to see available project templates
and wizards that you can use as a starting point for developing multi-tiered
applications.
Note Support for multi-tiered applications is available only in the Client/Server and
Enterprise versions.
purpose of creating and managing COM objects. COM objects can be transparently
extended, modified, and updated because unique identifiers are used to create them
and to access their interfaces.
Using Delphi to create COM-based applications offers many business solutions, from
improving software design by using interfaces internally in an application, to
creating objects that can interact with other COM-based API objects on the system,
such as the Win95 Shell extensions, Web page support, and DirectX multimedia
support.
indicating they are transactional, or they may not. If these components contain ODBC
connections for Microsoft SQL Server, these connections become part of the
transaction, and MTS can talk directly with the ODBC Driver. MTS developers using
MIDAS gain thin client briefcase mode, automatic constraint and business rule
updates, data updates, and support for database engines other than Microsoft SQL
Server
Deploying applications
Delphi includes add-on tools to help with application deployment. For example,
InstallShield Express helps you to create an installation package for your application
that includes all of the files needed for running a distributed application. PVCS
Version Manager software is also available for tracking application updates.
If you are writing applications that you plan to distribute internationally, Delphi also
has tools and guidelines for internationalizing and localizing applications. For
example, you can use the string table editor to edit binary RES files created while
using the Resource DLL wizard.
Index I-1
ellipse buttons 3-13 Menu editor 3-13 Project Options dialog box 4-5
environment options 4-7 menus 3-2 project templates
Environment Options dialog Microsoft Transaction Server specifying default 4-6
box 4-8 (MTS) 5-13 projects 2-13, 3-1
errors 5-7 MIDAS 5-10 defaults 4-6
event handlers 3-14 MTS 5-13 options 4-5
default 3-14 multi-tiered application 5-10 restoring defaults 4-6
viewing 2-4 Multi-tiered Distributed properties
events 2-4 Application Services Suite initial values 3-3
navigating 2-4 (MIDAS) 5-10 setting 3-3, 3-13
Events page (Object viewing 3-2
Inspector) 2-4 N property editors 3-13
exception handling 5-7 activating 3-13
New Application command 3-1 initializing objects and 3-3
F PVCS Version Manager 5-14
O
fields 3-5 R
File Save dialog box 3-14 object hierarchy 5-2
files Object Inspector 3-2 remote connections 2-11
saving 3-14 creating event handlers 3-14 Remote Data Broker 5-10
folders 3-1 overview 2-3 remote debugging 2-10
Font editor 3-13 setting properties 3-3, 3-13 repository 2-11
fonts viewing properties 3-2 restoring project defaults 4-6
customizing 3-13 Object Repository 2-11, 4-6 reusing objects 2-11
form wizards 4-7 default forms 4-7 right-click menus 2-14
forms 3-2 Object Request Broker runtime packages 5-7
adding components 2-2 (ORB) 5-12
adding objects 3-3 to 3-4 objects 2-11, 3-2 S
specifying default 4-7 adding 3-3 to 3-4
initializing 3-3 sample database 3-6
G instantiating 3-4 SaveDialog component 3-14
setting properties 3-3, 3-13 saving
grid 3-5 storing as templates 2-11 files 3-14
OCX 5-12 setting property values
H ODBC 5-14 tutorial 3-3, 3-13
OLE 5-12 single-tiered application 5-10
Help 2-15 OLEnterprise 5-10 source code 2-5
customizing 4-11 OnClick event 3-14 default
list of Help files 1-2 online help 2-15 event handlers 3-14
OpenHelp 4-11 source files 3-1
I Oracle8 5-8 changing 2-4
SQL Explorer 2-11, 5-9
IDE 2-1, 5-1
adding components 4-10 P SQL Links 5-10
support 1-4
initializing packages 5-7
objects 3-3 default container 4-10
InstallShield Express 5-14 installing 4-10
T
instantiation palette pages 3-3 templates 2-11
objects 3-4 panels creating component 4-11
interfaces 3-2 removing captions 3-11 specifying default 4-6
designing 3-3 parent windows 3-2 text
international applications 5-14 Picture editor 3-13 adding to forms 3-12
predefined components 3-3 controls 3-12
M project files 2-13 setting fonts 3-13
Project Manager tool preferences 4-7
memos
overview 2-13 tool windows 2-8
creating 3-12
Index I-3
I-4 Quick Start