1. Trang chủ
  2. » Công Nghệ Thông Tin

delphi 6 - quickstart

78 337 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Delphi 6 - Quickstart
Trường học Borland Software Corporation
Chuyên ngành Software Development
Thể loại hướng dẫn nhanh
Năm xuất bản 2001
Thành phố Scotts Valley
Định dạng
Số trang 78
Dung lượng 1,05 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

2-2The Component Palette, Form Designer, and Object Inspector.. In Delphi, the IDE includes the menus, toolbars, Component palette, Object Inspector, Object TreeView, Code editor, Code E

Trang 1

Quick Start

Borland Software Corporation

100 Enterprise Way, Scotts Valley, CA 95066-3249

Borland®

for Windows

Trang 2

Refer to the DEPLOY document located in the root directory of your Delphi 6 product for a complete list of files that you can distribute in accordance with the Delphi License Statement and Limited Warranty.

Borland 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 © 1983, 2001 Borland Software Corporation All rights reserved All Borland brands and product names are trademarks or registered trademarks of Borland Software Corporation Other product names are trademarks or registered trademarks of their respective holders

Printed in the U.S.A

HDE1360WW21000 1E0R0501

0102030405-9 8 7 6 5 4 3 2 1

PDF

Trang 3

The menus and toolbars 2-2

The Component Palette, Form Designer,

and Object Inspector 2-3

The Object TreeView 2-4

The Object Repository 2-5

The Code Editor 2-6

Code Insight 2-7

Class Completion 2-8

Code Browsing 2-8

The Diagram page 2-9

Viewing form code 2-10

The Code Explorer 2-11

The Project Manager 2-12

The Project Browser 2-13

To-do lists 2-13

Chapter 3

Creating a project 3-1

Adding data modules 3-2

Building the user interface 3-2

Placing components on a form 3-2

Setting component properties 3-3

Writing code 3-5

Writing event handlers 3-5

Using the VCL and CLX libraries 3-5

Compiling and debugging projects 3-6

Chapter 4

Starting a new application 4-1Setting property values 4-2Adding components to the form 4-3Adding support for a menu and a toolbar 4-6Adding actions to the action manager 4-7Adding standard actions to the

action manager 4-9Adding images to the image list 4-10Adding a menu 4-13Adding a toolbar 4-14Clearing the text area (optional) 4-15Writing event handlers 4-16Creating an event handler for the

New command 4-16Creating an event handler for the

Open command 4-18Creating an event handler for the

Save command 4-19Creating an event handler for the

Save As command 4-20Creating a Help file 4-22Creating an event handler for the

Help Contents command 4-22Creating an event handler for the

Help Index command 4-23Creating an About box 4-24Completing your application 4-26

Chapter 5

Organizing your work area 5-1Arranging menus and toolbars 5-1Docking tool windows 5-2Saving desktop layouts 5-4

Contents

Trang 4

Customizing the Component palette 5-5

Arranging the Component palette 5-5

Creating component templates 5-6

Installing component packages 5-7

Using frames 5-8

Adding ActiveX controls 5-9

Setting project options 5-9

Setting default project options 5-9

Specifying project and form templates

as the default 5-9Adding templates to the Object

Repository 5-10Setting tool preferences 5-11Customizing the Form Designer 5-11Customizing the Code Editor 5-12Customizing the Code Explorer 5-12

Trang 5

I n t r o d u c t i o n 1-1

C h a p t e r

1

Chapter1Introduction

This Quick Start provides an overview of the Delphi development environment to get

you started using the product right away It also tells you where to look for details about the tools and features available in Delphi

Chapter 2, “A tour of the desktop” describes the main tools on the Delphi desktop, or integrated desktop environment (IDE) Chapter 3, “Programming with Delphi” explains how you use some of these tools to create an application Chapter 4,

“Creating a text editor—a tutorial” takes you step by step through a tutorial to write

a program for a text editor Chapter 5, “Customizing the desktop” describes how you can customize the Delphi IDE for your development needs

What is Delphi?

Delphi is an object-oriented, visual programming environment for rapid application development (RAD) Using Delphi, you can create highly efficient applications for Microsoft Windows 2000, Windows 98, and Windows NT with a minimum of manual coding Delphi also provides a simple cross-platform solution when used in conjunction with Kylix, Borland’s RAD tool for Linux Delphi provides all the tools you need to develop, test, and deploy applications, including a large library of reusable components, a suite of design tools, application and form templates, and programming wizards

Trang 6

Reference (CLX) It includes all the material in the Delphi Developer’s Guide, Object Pascal Language Guide, and a host of Help files for other features bundled with Delphi.

To view the table of contents, choose Help|Delphi Help and Help|Delphi Tools, and click the Contents tab To look up VCL or CLX objects or any other topic, click the Index or Find tab and type your request

F1 Help

You can get context-sensitive Help on the VCL, CLX, and any part of the

development environment, including menu items, dialog boxes, toolbars, and

components by selecting the item and pressing F1.

Press F1 on a property or

event name in the Object Inspector to display VCL Help.

In the Code editor, press

F1 on a language, VCL, or

CLX element.

Trang 7

This Quick Start is an introduction to Delphi To order additional printed

documentation, such as the Developer’s Guide, refer to shop.borland.com.

Trang 8

D e v e l o p e r s u p p o r t s e r v i c e s a n d W e b s i t e

Developer support services and Web site

Borland also offers a variety of support options to meet the needs of its diverse developer community To find out about support, refer to

http://www.borland.com/devsupport/

From the Web site, you can access many newsgroups where Delphi developers exchange information, tips, and techniques The site also includes a list of books about Delphi, additional Delphi technical documents, and Frequently Asked Questions (FAQs)

Typographic conventions

This manual uses the typefaces described below to indicate special text

Table 1.1 Typographic conventions

Typeface Meaning

Monospace type Monospaced type represents text as it appears on screen or in code It also

represents anything you must type.

Boldface Boldfaced words in text or code listings represent reserved words or compiler

options.

Italics Italicized words in text represent Delphi identifiers, such as variable or type

names Italics are also used to emphasize certain words, such as new terms.

Keycaps This typeface indicates a key on your keyboard For example, “Press Esc to exit

a menu.”

Trang 9

A t o u r o f t h e d e s k t o p 2-1

C h a p t e r

2

Chapter2A tour of the desktop

This chapter explains how to start Delphi and gives you a quick tour of the main parts and tools of the desktop, or integrated desktop environment (IDE)

Starting Delphi

You can start Delphi in the following ways:

• Double-click the Delphi icon (if you’ve created a shortcut)

• Choose Programs|Borland Delphi 6|Delphi 6 from the Windows Start menu

• Choose Run from the Windows Start menu, then enter Delphi32

• Double-click Delphi32.exe in the Delphi\Bin directory

The IDE

When you first start Delphi, you’ll see some of the major tools in the IDE In Delphi, the IDE includes the menus, toolbars, Component palette, Object Inspector, Object TreeView, Code editor, Code Explorer, Project Manager, and many other tools The particular features and components available to you will depend on which edition of Delphi you’ve purchased

Trang 10

T h e m e n u s a n d t o o l b a r s

Delphi’s development model is based on two-way tools This means that you can

move back and forth between visual design tools and text-based code editing For example, after using the Form Designer to arrange buttons and other elements in a graphical interface, you can immediately view the form file that contains the textual description of your form You can also manually edit any code generated by Delphi without losing access to the visual programming environment

From the IDE, all your programming tools are within easy reach You can design graphical interfaces, browse through class libraries, write code, and compile, test, debug, and manage projects without leaving the IDE

To learn about organizing and configuring the IDE, see Chapter 5, “Customizing the desktop.”

The menus and toolbars

The main window, which occupies the top of the screen, contains the main menu, toolbars, and Component palette

The Component palette contains ready-made components to add to your projects.

Code editor displays code to view and edit.

The Form Designer contains a blank form

on which to start designing the user interface for your application An application can include several forms.

The Code Explorer shows you the classes, variables, and routines in your unit and lets you navigate quickly.

The Object Inspector is

used to change objects’

properties and select event

handlers.

The Object TreeView displays a

hierarchical view of your components’

Trang 11

You can right-click on many tools and icons to display a menu of commands

appropriate to the object you are working with These are called context menus.

The toolbars are also customizable You can add commands you want to them or move them to different locations For more information, see “Arranging menus and toolbars” on page 5-1 and “Saving desktop layouts” on page 5-4

For more information

If you need help on any menu option, point to it and press F1.

The Component Palette, Form Designer, and Object Inspector

The Component palette, Form Designer, Object Inspector, and Object TreeView work together to help you build a user interface for your application

The Component palette includes tabbed pages with groups of icons representing visual

or nonvisual VCL and CLX components The pages divide the components into various functional groups For example, the Standard, Additional, and Win32 pages include windows controls such as an edit box and up/down button; the Dialogs page

You can use the right-click menu to hide any toolbar To display a toolbar if it’s not showing, choose View|Toolbars and check the one you want.

To find out what a button does, point to it for a moment until a tooltip appears.

Run

Open project

Save all Add file to

project Open

Save

New form

Remove file from project New Toggle form/unit

View form

View unit

Standard toolbar

Pause

Trace into

Step over

Set debug desktop

Save current desktop

New WebSnap Page Module

New WebSnap Data Module

External Editor

Internet toolbar

New WebSnap Application

Trang 12

After you place components on the form, or Form Designer, you can arrange

components the way they should look on your user interface For the components

you place on the form, use the Object Inspector to set design-time properties, create

event handlers, and filter visible properties and events, making the connection between your application’s visual appearance and the code that makes your

application run See “Placing components on a form” on page 3-2

For more information

See “Component palette” in the online Help index

The Object TreeView

The Object TreeView displays a component’s sibling and parent-child relationships

in a hierarchical, or tree diagram The tree diagram is synchronized with the Object Inspector and the Form Designer so that when you change focus in the Object TreeView, both the Object Inspector and the form change focus

You can use the Object TreeView to change related components’ relationships to each other For example, if you add a panel and check box component to your form, the

Component palette pages, grouped by function

Components

Click to view more pages.

After you place components on a form, the Object Inspector dynamically changes the set of properties it displays, based on the component selected.

Trang 13

A t o u r o f t h e d e s k t o p 2-5

T h e O b j e c t R e p o s i t o r y

two components are siblings But in the Object TreeView, if you drag the check box

on top of the panel icon, the check box becomes the child of the panel

If an object’s properties have not been completed, the Object TreeView displays a red question mark next to it You can also double-click any object in the tree diagram to open the Code editor to a place where you can write an event handler

If the Object TreeView isn’t displayed, choose View|Object TreeView

The Object TreeView is especially useful for displaying the relationships between database objects

For more information

See “Object TreeView” in the online Help index

The Object Repository

The Object Repository contains forms, dialog boxes, data modules, wizards, DLLs, sample applications, and other items that can simplify development Choose File|New|Other to display the New Items dialog box when you begin a project The New

The Object TreeView,

Object Inspector, and the

Form Designer work

together When you click an

object on your form, it

automatically changes the

focus in both the Object

TreeView and the Object

Inspector and vice versa.

Press Alt-Shift-F11 to focus

on the Object TreeView.

Trang 14

T h e C o d e E d i t o r

Items dialog box is the same as the Object Repository Check the Repository to see if

it contains an object that resembles one you want to create

To edit or remove objects from the Object Repository, either choose Tools|Repository

or right-click in the New Items dialog box and choose Properties

To add project and form templates to the Object Repository, see “Adding templates

to the Object Repository” on page 5-10

For more information

See “Object Repository” in the online Help index The objects available to you will depend on which edition of Delphi you purchased

The Code Editor

As you design the user interface for your application, Delphi generates the

underlying Object Pascal code When you select and modify the properties of forms and objects, your changes are automatically reflected in the source files You can add

The Repository’s tabbed pages include

objects like forms, frames, units, and

wizards to create specialized items.

When you’re creating an item based on

one from the Object Repository, you

can copy, inherit, or use the item:

Copy (the default) creates a copy of

the item in your project Inherit means

changes to the object in the Repository

are inherited by the one in your project

Use means changes to the object in

your project are inherited by the object

in the Repository.

You can add, remove, or

rename tabbed pages from

the Object Repository.

Click the arrows to change

the order in which a tabbed

page appears in the New

Items dialog box.

Trang 15

The Code Insight tools display context-sensitive pop-up windows

Table 2.1 Code Insight tools

Tool How it works

Code completion Type a class name followed by a dot (.) to display a list of

properties, methods, and events appropriate to the class, select

it, and press Enter In the interface section of your code you can

select more than one item Type the beginning of an assignment

statement and press Ctrl+space to display a list of valid values for

the variable Type a procedure, function, or method name to bring up a list of arguments.

Code parameters Type a method name and an open parenthesis to display the

syntax for the method’s arguments.

Tooltip expression evaluation While your program has paused during debugging, point to any

variable to display its current value.

Tooltip symbol insight While editing code, point to any identifier to display its

declaration.

Code templates Press Ctrl+J to see a list of common programming statements that

you can insert into your code You can create your own templates in addition to the ones supplied with Delphi.

Trang 16

T h e C o d e E d i t o r

To turn these tools on or off, choose Tools|Editor Options and click the Code Insight tab Check or uncheck the tools in the Automatic features section

Class Completion

Class completion generates skeleton code for classes Place the cursor anywhere

within a class declaration of the interface section of a unit and press Ctrl+Shift+C or

right-click and choose Complete Class at Cursor Delphi automatically adds private

read and write specifiers to the declarations for any properties that require them,

then creates skeleton code for all the class’s methods You can also use class

completion to fill in class declarations for methods you’ve already implemented

To turn on class completion, choose Tools|Environment Options, click the Explorer tab, and make sure Finish incomplete properties is checked

For more information

See “Code Insight” and “class completion” in the online Help index

Code Browsing

While passing the mouse over the name of any class, variable, property, method, or other identifier, the pop-up menu called Tooltip Symbol Insight displays where the

identifier is declared Press Ctrl and the cursor turns into a hand, the identifier turns

blue and is underlined, and you can click to jump to the definition of the identifier.The Code editor has forward and back buttons like the ones on Web browsers As you jump to these definitions, the Code editor keeps track of where you’ve been in

With code completion, when you type the dot

in Button1. Delphi displays a list of properties, methods, and events for the class

As you type, the list automatically filters to the selection that pertains to that class Select an

item on the list and press Enter to add it to

Trang 17

A t o u r o f t h e d e s k t o p 2-9

T h e C o d e E d i t o r

the code You can click the drop-down arrows next to the Forward and Back buttons

to move forward and backward through a history of these references

You can also move between the declaration of a procedure and its implementation by

pressing Ctrl+Shift+↑ or Ctrl+Shift+↓.

To customize your code editing environment, see “Customizing the Code Editor” on page 5-12

For more information

See “Code editor” in the online Help index

The Diagram page

The bottom of the Code editor may contain one or more tabs, depending on which edition of Delphi you have The Code page, where you write all your code, appears

in the foreground by default The Diagram page displays icons and connecting lines representing the relationships between the components you place on a form or data module These relationships include siblings, parent to children, or components to properties

To create a diagram, click the Diagram page From the Object TreeView, simply drag one or multiple icons to the Diagram page to arrange them vertically To arrange

them horizontally, press Shift while dragging When you drag icons with children or component-property dependencies onto the page, the lines, or connectors,

parent-that display the dependent relationships are automatically added For example, if you add a dataset component to a data module and drag the dataset icon plus its property icons to the Diagram page, the property connector automatically connects the property icons to the dataset icon

For components that don’t have dependent relationships but where you want to show one, use the toolbar buttons at the top of the Diagram page to add one of four

Click the back arrow to return to the last place you were working in your code Then click the forward arrow to move forward again.

Press Ctrl and click or right-click and click Find

Declaration to jump to the definition of the identifier.

The Code editor maintains a list of the definitions you jumped to.

Trang 18

For more information

See “diagram page” in the online Help index

Viewing form code

Forms are a very visible part of most Delphi projects—they are where you design the user interface of an application Normally, you design forms using Delphi‘s visual tools, and Delphi stores the forms in form files Form files (.dfm, or xfm for a CLX application) describe each component in your form, including the values of all persistent properties To view and edit a form file in the Code editor, right-click the form and select View as Text To return to the graphic view of your form, right-click and choose View as Form

Use the Diagram page toolbar buttons—Property, Master/Detail and Lookup—

to designate the relationship between components and components and their properties The appearance

of the connecting line varies for each type of relationship Click the Comment block button to add a comment, and the Allude connector button to draw a connection

to another comment or icon.

From the Object TreeView, drag

the icons of the components to

the Diagram page.

To view other diagrams you’ve named in the current project, click the drop-down list box.

Type a name and description for your diagram.

Trang 19

A t o u r o f t h e d e s k t o p 2-11

T h e C o d e E x p l o r e r

You can save form files in either text (the default) or binary format Choose Tools|Environment Options, click the Designer page, and check or uncheck the New forms

as text check box to designate which format to use for newly created forms

For more information

See “form files” in the online Help index

The Code Explorer

When you open Delphi, the Code Explorer is docked to the left of the Code editor window, depending on whether the Code Explorer is available in the edition of Delphi you have The Code Explorer displays the table of contents as a tree diagram for the source code open in the Code editor, listing the types, classes, properties, methods, global variables, and routines defined in your unit It also shows the other

units listed in the uses clause.

You can use the Code Explorer to navigate in the Code editor For example, if you double-click a method in the Code Explorer, a cursor jumps to the definition in the class declaration in the interface part of the unit in the Code editor

Use View As Text to view a text description

of the form’s attributes in the Code editor.

Trang 20

T h e P r o j e c t M a n a g e r

To configure how the Code Explorer displays its contents, choose Tools|

Environment Options and click the Explorer tab See “Customizing the Code

Explorer” on page 5-12

For more information

See “Code Explorer” in the online Help index

The Project Manager

When you first start Delphi, it automatically opens a new project, as shown on page 2-2 A project includes several files that make up the application or DLL you are going to develop You can view and organize these files—such as form, unit,

resource, object, and library files—in a project management tool called the Project Manager To display the Project Manager, choose View|Project Manager

You can use the Project Manager to combine and display information on related

projects into a single project group By organizing related projects into a group, such as

multiple executables, you can compile them at the same time To change project options, such as compiling a project, see “Setting project options” on page 5-9

For more information

See “Project Manager” in the online Help index

Double-click an item in the Code Explorer and the cursor moves to that item’s implementation in the

Code editor Press Ctrl+Shift+E to

move the cursor back and forth between the last place you were in the Code Explorer and Code editor Each item in the Code Explorer has

an icon that designates its type.

Trang 21

A t o u r o f t h e d e s k t o p 2-13

T h e P r o j e c t B r o w s e r

The Project Browser

The Project Browser examines a project in detail The Browser displays classes, units, and global symbols (types, properties, methods, variables, and routines) your project declares or uses in a tree diagram Choose View|Browser to display the Project Browser

By default, the Project Browser displays the symbols from units in the current project only You can change the scope to display all symbols available in Delphi Choose Tools|Environment Options, and on the Explorer page, check All symbols (VCL included)

For more information

See “Project Browser” in the online Help index

Globals displays classes, types, properties, methods, variables, and routines.

Classes displays classes in a hierarchical diagram.

Units displays units, identifiers declared in each unit, and the other units that use and are used by each unit.

Trang 22

T o - d o l i s t s

directly in the source code Choose View|To-Do List to add or view information associated with a project

For more information

See “to-do lists” in the online Help index

Right-click on a to-do list to display commands that let you sort and filter the list.

Click the check

box when you’re

done with an item.

Trang 23

P r o g r a m m i n g w i t h D e l p h i 3-1

C h a p t e r

3

The following sections provide an overview of software development with Delphi, including creating a project, working with forms, writing code, and compiling, debugging, deploying, and internationalizing applications, and including the types

of projects you can develop

Creating a project

A project is a collection of files that are either created at design time or generated when you compile the project source code When you first start Delphi, a new project opens It automatically generates a project file (Project1.dpr), unit file (Unit1.pas), and resource file (Unit1.dfm; Unit1.xfm for CLX applications), among others

If a project is already open but you want to open a new one, choose either File|New| Application or File|New|Other and double-click the Application icon File|New|Other opens the Object Repository, which provides additional forms, modules, and frames as well as predesigned templates such as dialog boxes to add to your project

To learn more about the Object Repository, see “The Object Repository” on page 2-5.When you start a project, you have to know what you want to develop, such as an application or DLL To read about what types of projects you can develop with Delphi, see “Types of projects” on page 3-8

For more information

See “projects” in the online Help index

Trang 24

B u i l d i n g t h e u s e r i n t e r f a c e

Adding data modules

A data module is a type of form that contains nonvisual components only Nonvisual

components can be placed on ordinary forms alongside visual components But if

you plan on reusing groups of database and system objects, or if you want to isolate the parts of your application that handle database connectivity and business rules, data modules provide a convenient organizational tool

To create a data module, choose File|New|Data Module Delphi opens an empty data module, which displays an additional unit file for the module in the Code Editor, and adds the module to the current project as a new unit Add nonvisual components to a data module in the same way as you would to a form

When you reopen an existing data module, Delphi displays its components

For more information

See “data modules” in the online Help index

Building the user interface

With Delphi, you first create a user interface (UI) by selecting components from the Component palette and placing them on the main form

Placing components on a form

To place components on a form, either:

1 Double-click the component; or

2 Click the component once and then click the form where you want the component

to appear

Double-click a nonvisual component on the Component palette to place the component in the data module.

Click a component on the Component palette

Trang 25

P r o g r a m m i n g w i t h D e l p h i 3-3

B u i l d i n g t h e u s e r i n t e r f a c e

Select the component and drag it to wherever you want on the form

For more information

See “Component palette” in the online Help index

Setting component properties

After you place components on a form, set their properties and code their event handlers Setting a component’s properties changes the way a component appears and behaves in your application When a component is selected on a form, its properties and events are displayed in the Object Inspector

Many properties have simple values—such as names of colors, True or False, and

integers For Boolean properties, you can double-click the word to toggle between

True and False Some properties have associated property editors to set more complex

Then click where you want to place it on the form.

Or choose a component from

an alphabetical list.

Or use this drop-down list to select an object Here, Button1 is selected, and its properties are displayed.

You can also click a plus sign to open a detail list.

Select a property and change its value in the right column.

Click an ellipsis to open

a dialog box where you can change the properties of a helper object.

You can select a component, or object, on the form by clicking on it.

Trang 26

in the Object Inspector you can set the PopupMenu property to PopupMenu1, which

displays all of the pop-up menu’s properties

For more information

See “Object Inspector” in the online Help index

Double-click here to change the value from

Set the Button

appear when you

click the plus sign (+).

Trang 27

Writing event handlers

Your code may need to respond to events that might occur to a component at runtime An event is a link between an occurrence in the system, such as clicking a button, and a piece of code that responds to that occurrence The responding code is

an event handler This code modifies property values and calls methods

To view predefined event handlers for a component on your form, select the

component and, on the Object Inspector, click the Events tab

For more information

See “events” in the online Help index

Using the VCL and CLX libraries

Delphi comes with two class libraries made up of objects, some of which are also components or controls, that you use when writing code You can use the Visual Component Library (VCL) for Windows applications and Borland Component Library for Cross Platform (CLX) for Linux applications These libraries include objects that are visible at runtime—such as edit controls, buttons, and other user interface elements—as well as nonvisual controls like datasets and timers The

Select an existing event handler from the drop- down list.

Or double-click in the value column, and Delphi generates skeleton code for the new event handler.

Here, Button1 is selected and its type is displayed: TButton

Click the Events tab in the Object Inspector to see the events that the Button component can handle

Trang 28

C o m p i l i n g a n d d e b u g g i n g p r o j e c t s

following diagram below shows some of the principal classes that make up the VCL The CLX hierarchy is similar

Objects descended from TComponent have properties and methods that allow them to

be installed on the Component palette and added to Delphi forms and data modules Because VCL and CLX components are hooked into the IDE, you can use tools like the Form Designer to develop applications quickly

Components are highly encapsulated For example, buttons are preprogrammed to

respond to mouse clicks by firing OnClick events If you use a VCL or CLX button

control, you don’t have to write code to handle generated events when the button is clicked; you are responsible only for the application logic that executes in response to the click itself

Most editions of Delphi come with VCL and CLX source code and examples of Object Pascal programming techniques

For more information

See “Visual Component Library Reference” and “CLX Reference” in the Help contents and “VCL” in the online Help index See http://www.borland.com/delphi for open source and licensing options on CLX

Compiling and debugging projects

After you have written your code, you will need to compile and debug your project With Delphi, you can either compile your project first and then separately debug it,

or you can compile and debug in one step using the integrated debugger To compile your program with debug information, choose Project|Options, click the Compiler page, and make sure Debug information is checked

Delphi uses an integrated debugger so that you can control program execution, watch variables, and modify data values You can step through your code line by line, examining the state of the program at each breakpoint To use the integrated

TObject TPersistent

TStream Exception

TGraphic TGraphicsObject

TControl TCommonDialog TMenu

TDataSet

TWinControl TGraphicControl

TCustomControl TScrollingWinControl

TApplication

TComObject

TCollection

TField TInterface

TCustomForm

Most visual controls inherit from TWinControl or in CLX, TWidgetControl.

Trang 29

To learn how to combine debugging windows for more convenient use, see “Docking tool windows” on page 5-2.

Once you set up your desktop as you like it for debugging, you can save the settings

as the debugging or runtime desktop This desktop layout will be used whenever you are debugging any application For details, see “Saving desktop layouts” on page 5-4

For more information

See “debugging” and “integrated debugger” in the online Help index

Run button

Choose any of the debugging commands from the Run menu Some commands are also available on the toolbar.

You can combine several debugging windows for easier use.

Trang 30

D e p l o y i n g a p p l i c a t i o n s

Deploying applications

You can make your application available for others to install and run by deploying it When you deploy an application, you will need all the required and supporting files, such as the executables, DLLs, package files, and helper applications Delphi comes bundled with a setup toolkit called InstallShield Express that helps you create an installation program with these files To install InstallShield Express, from the Delphi setup screen, choose InstallShield Express Custom Edition for Delphi

For more information

See “deploying, applications” in the online Help index

Internationalizing applications

Delphi offers several features for internationalizing and localizing applications The IDE and the VCL support input method editors (IMEs) and extended character sets to internationalize your project Delphi includes a translation suite, not available in all editions of Delphi, for software localization and simultaneous development for different locales With the translation suite, you can manage multiple localized versions of an application as part of a single project

The translation suite includes three integrated tools:

• Resource DLL wizard, a DLL wizard that generates and manage resource DLLs

• Translation Manager, a table for viewing and editing translated resources

• Translation Repository, a shared database to store translations

To open the Resource DLL wizard, choose File|New|Other and double-click the Resource DLL Wizard icon To configure the translation tools, choose Tools|

Translation Tools Options

For more information

See “international applications” in the online Help index

Types of projects

All editions of Delphi support general-purpose 32-bit Windows programming, DLLs, packages, custom components, multithreading, COM (Component Object Model) and automation controllers, and multiprocess debugging Some editions support server applications such as Web server applications, database applications, COM servers, multi-tiered applications, CORBA, and decision-support systems

For more information

To see what tools your edition supports, refer to the feature list on

www.borland.com/delphi

Trang 31

Windows-specific features supported on Delphi will not port directly to Linux environments.

For more information

To see which components are available for developing cross-platform applications, see “CLX Reference” in the online Help contents

Web server applications

A Web server application works with a Web server by processing a client’s request and returning an HTTP message in the form of a Web page To publish data for the Web, Delphi includes two different technologies, depending on what edition of Delphi you have

To develop a basic Web server application, you create a Web module to dispatch requests, define actions, create HTML pages, and write event handlers for both Windows and Linux applications To create a WebBroker Web server application, choose File|New|Other and double-click the Web Server Application icon You can add components to your Web module from the Internet and InternetExpress

Component palette pages

WebSnap adds to this functionality with adapters, additional dispatchers, additional page producers, session support, and Web page modules To create a new WebSnap server application, select File|New|Other, click the WebSnap page, and double-click the Web Server Application icon You can add WebSnap components from the WebSnap Component palette page

You can create an application to run on various Web server application types, including a test server to help you debug your Web server application.

Choose whether you want a data module or a page module, which displays your HTML page

as you work.

You can also access the

WebSnap Application data

module by choosing View|

Toolbars|Internet, and

clicking the New WebSnap

Application icon.

Trang 32

T y p e s o f p r o j e c t s

For more information

See “Web applications” in the online Help index

Database applications

Delphi offers a variety of database and connectivity tools to simplify the

development of database applications

To create a database application, first design your interface on a form using the Data Controls page components Second, add a data source to a data module using the Data Access page Third, to connect to various database servers, add a dataset and data connection component to the data module from the previous or corresponding pages of the following connectivity tools:

• dbExpress is a collection of database drivers for cross-platform applications that provide fast access to SQL database servers, including DB2, InterBase, MySQL, and Oracle With a dbExpress driver, you can access databases using

unidirectional datasets

• The Borland Database Engine (BDE) is a collection of drivers that support many popular database formats, including dBASE, Paradox, FoxPro, Microsoft Access, and any ODBC data source SQL Links drivers, available with some versions of Delphi, support servers such as Oracle, Sybase, Informix, DB2, SQL Server, and InterBase

• ActiveX Data Objects (ADO) is Microsoft's high-level interface to any data source, including relational and nonrelational databases, e-mail and file systems, text and graphics, and custom business objects

• InterBase Express (IBX) components are based on the custom data access Delphi component architectures IBX applications provide access to advanced InterBase features and offer the highest performance component interface for InterBase 5.5 and later IBX is compatible with Delphi’s library of data-aware components Certain database connectivity tools are not available in all editions of Delphi

For more information

See “database applications” in the online Help index

BDE Administrator

Use the BDE Administrator (BDEAdmin.exe) to configure BDE drivers and set up the aliases used by data-aware VCL controls to connect to databases

For more information

From the Windows Start menu, choose Programs|Borland Delphi 6|BDE

Administrator Then choose Help|Contents

Trang 33

P r o g r a m m i n g w i t h D e l p h i 3-11

T y p e s o f p r o j e c t s

SQL Explorer (Database Explorer)

The SQL Explorer (DBExplor.exe) lets you browse and edit databases You can use it

to create database aliases, view schema information, execute SQL queries, and maintain data dictionaries and attribute sets

For more information

From the Delphi main menu, choose Database|Explore Then choose Help|

Contents Or see “Database Explorer” in the online Help index

Database Desktop

The Database Desktop (DBD32.exe) lets you create, view, and edit Paradox and dBase database tables in a variety of formats

For more information

From the Windows Start menu, choose Programs|Borland Delphi 6|Database Desktop Then choose Help|User’s Guide Contents

Data Dictionary

When you use the BDE, the Data Dictionary provides a customizable storage area, independent of your applications, where you can create extended field attribute sets that describe the content and appearance of data The Data Dictionary can reside on a remote server to share additional information

For more information

Choose Help|Delphi Tools to see “Data Dictionary.”

You can either install custom components from third-party vendors or create your own To create a new component, choose Component|New Component to display the New Component wizard To install components provided by a third party, see

“Installing component packages” on page 5-7

For more information

See Part V, “Creating custom components,” in the Developer’s Guide and

“components, creating” in the online Help index

Trang 34

T y p e s o f p r o j e c t s

DLLs

Dynamic-link libraries (DLLs) are compiled modules containing routines that can be called by applications and by other DLLs A DLL contains code or resources typically used by more than one application Choose File|New|Other and double-click the DLL Wizard icon to create a template for a DLL

For more information

See “DLLs” in the online Help index

COM and ActiveX

Delphisupports Microsoft’s COM standard and provides wizards for creating ActiveX controls Choose File|New|Other and click the ActiveX tab to access the wizards Sample ActiveX controls are installed on the ActiveX page of the

Component palette Numerous COM server components are provided on the Servers tab of the Component palette You can use these components as if they were VCL components For example, you can place one of the Microsoft Word components onto

a form to bring up an instance of Microsoft Word within an application interface

For more information

See “COM” and “ActiveX” in the online Help index

Type libraries

Type libraries are files that include information about data types, interfaces, member functions, and object classes exposed by an ActiveX control or server By including a type library with your COM application or ActiveX library, you make information about these entities available to other applications and programming tools Delphi provides a Type Library editor for creating and maintaining type libraries

For more information

See “type libraries” in the online Help index

Trang 35

C r e a t i n g a t e x t e d i t o r — a t u t o r i a l 4-1

C h a p t e r

4

This tutorial takes you through the creation of a text editor complete with menus, a toolbar, and a status bar

Note This tutorial is for all editions of Delphi and is for the Windows platform only

Starting a new application

Before beginning a new application, create a directory to hold the source files:

1 Create a directory called TextEditor in your C:\Program Files\Borland\Delphi6\Projects directory

2 Open a new project

Each application is represented by a project When you start Delphi, it creates a

blank project by default If another project is already open, choose File|New| Application to create a new project

When you open a new project, Delphi automatically creates the following files:

• Project1.dpr: a source-code file associated with the project This is called a project file.

• Unit1.pas: a source-code file associated with the main project form This is called

Trang 36

S e t t i n g p r o p e r t y v a l u e s

3 Choose File|Save All to save your files to disk When the Save dialog box appears:

• Navigate to your TextEditor folder

• Save Unit1 using the default name Unit1.pas

• Save the project using the name TextEditor.dpr (The executable will be named the same as the project name with an exe extension.)

Later, you can resave your work by choosing File|Save All

When you save your project, Delphi creates additional files in your project directory These files include TextEditor.dof, which is the Delphi Options file, TextEditor.cfg, which is the configuration file, and TextEditor.res, which is the Windows resource file You don’t need to worry about these files but don’t delete them

Setting property values

When you open a new project, Delphi displays the project’s main form, named Form1

by default You’ll create the user interface and other parts of your application by placing components on this form

Next to the form, you’ll see the Object Inspector, which you can use to set property values for the form and the components you place on it When you set properties, Delphi maintains your source code for you The values you set in the Object

Inspector are called design-time settings.

1 Find the form’s Caption property in the Object Inspector and type Text Editor

Tutorial replacing the default caption Form1 Notice that the caption in the heading

of the form changes as you type

The drop-down list at the top of the Object Inspector shows the currently selected component In this case,

the component is Form1 and its type is TForm1

When a component is selected, the Object Inspector displays its properties.

Trang 37

C r e a t i n g a t e x t e d i t o r — a t u t o r i a l 4-3

A d d i n g c o m p o n e n t s t o t h e f o r m

2 Run the form now by pressing F9, even though there are no components on it.

3 To return to the design-time view of Form1, do one of the following:

• Click the X in the upper right corner of the title bar of your application

(the runtime view of the form);

• Click the Exit application button in the upper left corner of the title bar and click Close;

• Choose View|Forms, select Form1, and click OK; or

• Choose Run|Program Reset

Adding components to the form

Before you start adding components to the form, you need to think about the best way to create the user interface (UI) for your application The UI is what allows the user of your application to interact with it and should be designed for ease of use Delphi includes many components that represent parts of an application For

example, there are components (derived from objects) on the Component palette that

make it easy to program menus, toolbars, dialog boxes, and many other visual and nonvisual program elements

The text editor application requires an editing area, a status bar for displaying information such as the name of the file being edited, menus, and perhaps a toolbar with buttons for easy access to commands The beauty of designing the interface using Delphi is that you can experiment with different components and see the results right away This way, you can quickly prototype an application interface

To start designing the text editor, add a RichEdit and a StatusBar component to the

form:

1 To create a text area, first add a RichEdit component To find the RichEdit

component, on the Win32 page of the Component palette, point to an icon on the

Without any components on it, the runtime view of the form looks similar to the design-time view, complete with the Minimize, Maximize, and Close buttons.

Trang 38

A d d i n g c o m p o n e n t s t o t h e f o r m

palette for a moment; Delphi displays a Help tooltip showing the name of the component

When you find the RichEdit component, either:

• Select the component on the palette and then click on the form where you want

to place the component; or

• Double-click the component to place it in the middle of the form

Each Delphi component is a class; placing a component on a form creates an instance of that class Once the component is on the form, Delphi generates the

code necessary to construct an instance of the object when your application is running

2 With the RichEdit component selected, in the Object Inspector, click the down arrow of the Align property and set it to alClient.

drop-Make sure the RichEdit1 component is

selected on the form.

Look for the Align property in the Object

Inspector Click the down arrow to display the property’s drop-down list.

Select alClient.

Trang 39

3 Double-click the StatusBar component on the Win32 page of the Component

palette This adds a status bar to the bottom of the form

4 To create one panel on the status bar to display the path and file name of the file being edited by your text editor:

• Make sure the status bar is selected

• After the SimpleText property, type untitled.txt When you use the text editor,

if the file being edited is not yet saved, the file name will be untitled.txt

• Click the (TStatusPanel) ellipse of the Panels property to open the Editing

StatusBar1.Panels dialog box

• Click the New Action button on the toolbar of the dialog box to add a panel

to the status bar

Tip You can also access the Editing StatusBar1.Panels dialog box by double-clicking

the status bar on your form

5 Click the X to close the Editing StatusBar1.Panels dialog box.

Now the main editing area of the user interface for the text editor is set up

Status bar Editing area

Click the New Action button

of the dialog box’s toolbar.

Or, right-click the dialog box to display a context menu Click Add to create a panel on the status bar that can hold persistent text.

The Panels property is a zero-based array

so that you can access each panel you create based on its unique index value By default, the first panel has a value of 0 Each time you click Add, you add an additional panel to the status bar.

Ngày đăng: 16/04/2014, 11:16

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN