dg.pdf

(15672 KB) Pobierz
Developer's Guide
Developer’s Guide
Borland ®
C ++ Builder 6
for Windows ®
Borland Software Corporation
100 Enterprise Way, Scotts Valley, CA 95066-3249
111507205.001.png
Refer to the DEPLOY document located in the root directory of your C++Builder product for a complete list of files
that you can distribute in accordance with the C++Builder License Statement and Limited Warranty.
Borland Software Corporation may have patents and/or pending patent applications covering subject matter in this
document. Please refer to the product CD or the About dialog box for the list of applicable patents. The furnishing of
this document does not give you any license to these patents.
C OPYRIGHT © 1983–2002 Borland Software Corporation. All rights reserved. All Borland brand and product names
are trademarks or registered trademarks of Borland Software Corporation in the United States and other countries.
All other marks are the property of their respective owners.
Printed in the U.S.A.
CPE1360WW21001 6E4R0102
02030405-9 8 7654321
PDF
Contents
Chapter 1
Introduction 1-1
What’s in this manual? . . . . . . . . . . . . . . 1-1
Manual conventions . . . . . . . . . . . . . . . . 1-3
Developer support services . . . . . . . . . . 1-3
Ordering printed documentation. . . . . . . 1-3
Specifying the stream position and size. . . . 4-3
Seeking to a specific position . . . . . . . . 4-4
Using Position and Size properties . . . . 4-4
Working with files . . . . . . . . . . . . . . . . . 4-4
Approaches to file I/O . . . . . . . . . . . . . 4-5
Using file streams . . . . . . . . . . . . . . . . 4-5
Creating and opening files using
file streams . . . . . . . . . . . . . . . . . 4-6
Using the file handle . . . . . . . . . . . . 4-6
Manipulating files . . . . . . . . . . . . . . . . 4-7
Deleting a file. . . . . . . . . . . . . . . . . 4-7
Finding a file . . . . . . . . . . . . . . . . . 4-7
Renaming a file. . . . . . . . . . . . . . . . 4-9
File date-time routines . . . . . . . . . . . 4-9
Copying a file . . . . . . . . . . . . . . . . 4-9
Working with ini files and the system
Registry. . . . . . . . . . . . . . . . . . . . . . 4-10
Using TIniFile and TMemIniFile . . . . . 4-10
Using TRegistryIniFile . . . . . . . . . . 4-11
Using TRegistry . . . . . . . . . . . . . . 4-12
Working with lists. . . . . . . . . . . . . . . . . 4-12
Common list operations . . . . . . . . . . . 4-13
Adding list items. . . . . . . . . . . . . . 4-13
Deleting list items . . . . . . . . . . . . . 4-14
Accessing list items . . . . . . . . . . . . 4-14
Rearranging list items . . . . . . . . . . . 4-14
Persistent lists . . . . . . . . . . . . . . . . . 4-14
Working with string lists . . . . . . . . . . . . . 4-15
Loading and saving string lists . . . . . . . 4-15
Creating a new string list . . . . . . . . . . . 4-16
Short-term string lists . . . . . . . . . . . 4-16
Long-term string lists . . . . . . . . . . . 4-16
Manipulating strings in a list. . . . . . . . . 4-17
Counting the strings in a list . . . . . . . 4-18
Accessing a particular string . . . . . . . 4-18
Locating items in a string list . . . . . . . 4-18
Iterating through strings in a list . . . . . 4-18
Adding a string to a list . . . . . . . . . . 4-18
Moving a string within a list . . . . . . . 4-18
Deleting a string from a list . . . . . . . . 4-19
Associating objects with a string
list . . . . . . . . . . . . . . . . . . . . . 4-19
Working with strings . . . . . . . . . . . . . . . 4-19
Wide character routines. . . . . . . . . . . . 4-20
Commonly used routines for
AnsiStrings . . . . . . . . . . . . . . . . . . 4-21
Part I
Programming with C++Builder
Chapter 2
Developing applications with
C++Builder 2-1
Integrated development environment . . . . . . 2-1
Designing applications . . . . . . . . . . . . . . 2-2
Creating projects . . . . . . . . . . . . . . . . . . 2-3
Editing code . . . . . . . . . . . . . . . . . . . . 2-3
Compiling applications . . . . . . . . . . . . . . 2-4
Debugging applications . . . . . . . . . . . . . . 2-4
Deploying applications . . . . . . . . . . . . . . 2-5
Chapter 3
Using the class libraries 3-1
Understanding the class libraries . . . . . . . . 3-1
Properties, methods, and events . . . . . . . 3-2
Properties . . . . . . . . . . . . . . . . . . 3-2
Methods . . . . . . . . . . . . . . . . . . . 3-3
Events . . . . . . . . . . . . . . . . . . . . 3-3
User events . . . . . . . . . . . . . . . . . 3-3
System events . . . . . . . . . . . . . . . . 3-3
Objects, components, and controls . . . . . . . . 3-4
TObject branch . . . . . . . . . . . . . . . . . 3-5
TPersistent branch . . . . . . . . . . . . . . . 3-6
TComponent branch . . . . . . . . . . . . . . 3-7
TControl branch . . . . . . . . . . . . . . . . 3-8
TWinControl/TWidgetControl branch . . . 3-9
Chapter 4
Using BaseCLX 4-1
Using streams . . . . . . . . . . . . . . . . . . . 4-2
Using streams to read or write data . . . . . 4-2
Stream methods for reading and
writing . . . . . . . . . . . . . . . . . . . 4-2
Reading and writing components. . . . . 4-3
Copying data from one stream to another . . 4-3
i
111507205.002.png
Commonly used routines for
null-terminated strings. . . . . . . . . . . . 4-23
Printing . . . . . . . . . . . . . . . . . . . . . . . 4-25
Converting measurements . . . . . . . . . . . . 4-25
Performing conversions . . . . . . . . . . . . 4-26
Performing simple conversions . . . . . . 4-26
Performing complex conversions . . . . . 4-26
Adding new measurement types . . . . . . . 4-26
Creating a simple conversion family
and adding units . . . . . . . . . . . . . . . 4-27
Declare variables . . . . . . . . . . . . . . 4-27
Register the conversion family . . . . . . 4-27
Register measurement units . . . . . . . . 4-27
Use the new units . . . . . . . . . . . . . . 4-28
Using a conversion function . . . . . . . . . 4-28
Declare variables . . . . . . . . . . . . . . 4-28
Register the conversion family . . . . . . 4-28
Register the base unit. . . . . . . . . . . . 4-29
Write methods to convert to and
from the base unit . . . . . . . . . . . . . 4-29
Register the other units. . . . . . . . . . . 4-29
Use the new units . . . . . . . . . . . . . . 4-29
Using a class to manage conversions. . . . . 4-30
Creating the conversion class . . . . . . . 4-30
Declare variables . . . . . . . . . . . . . . 4-31
Register the conversion family and
the other units . . . . . . . . . . . . . . . 4-31
Use the new units . . . . . . . . . . . . . . 4-32
Creating drawing spaces . . . . . . . . . . . . . 4-33
Associating menu events with event
handlers. . . . . . . . . . . . . . . . . . . . . 5-5
Deleting event handlers . . . . . . . . . . . . 5-6
Cross-platform and non-cross-platform
components . . . . . . . . . . . . . . . . . . . . 5-6
Adding custom components to the
Component palette . . . . . . . . . . . . . . 5-8
Chapter 6
Working with controls 6-1
Implementing drag and drop in controls. . . . . 6-1
Starting a drag operation . . . . . . . . . . . . 6-1
Accepting dragged items . . . . . . . . . . . . 6-2
Dropping items . . . . . . . . . . . . . . . . . 6-2
Ending a drag operation . . . . . . . . . . . . 6-3
Customizing drag and drop with a
drag object . . . . . . . . . . . . . . . . . . . 6-3
Changing the drag mouse pointer. . . . . . . 6-4
Implementing drag and dock in controls. . . . . 6-4
Making a windowed control a docking
site . . . . . . . . . . . . . . . . . . . . . . . . 6-4
Making a control a dockable child. . . . . . . 6-4
Controlling how child controls are
docked . . . . . . . . . . . . . . . . . . . . . 6-5
Controlling how child controls are
undocked . . . . . . . . . . . . . . . . . . . . 6-6
Controlling how child controls respond
to drag-and-dock operations . . . . . . . . . 6-6
Working with text in controls . . . . . . . . . . . 6-6
Setting text alignment. . . . . . . . . . . . . . 6-7
Adding scroll bars at runtime . . . . . . . . . 6-7
Adding the clipboard object . . . . . . . . . . 6-8
Selecting text . . . . . . . . . . . . . . . . . . . 6-8
Selecting all text . . . . . . . . . . . . . . . . . 6-8
Cutting, copying, and pasting text . . . . . . 6-9
Deleting selected text . . . . . . . . . . . . . . 6-9
Disabling menu items. . . . . . . . . . . . . . 6-9
Providing a pop-up menu . . . . . . . . . . 6-10
Handling the OnPopup event . . . . . . . . 6-10
Adding graphics to controls . . . . . . . . . . . 6-11
Indicating that a control is owner-
drawn . . . . . . . . . . . . . . . . . . . . . 6-11
Adding graphical objects to a string
list . . . . . . . . . . . . . . . . . . . . . . . 6-12
Adding images to an application . . . . 6-12
Adding images to a string list . . . . . . 6-12
Drawing owner-drawn items. . . . . . . 6-13
Sizing owner-draw items . . . . . . . . . . . 6-14
Drawing owner-draw items . . . . . . . . . 6-14
Chapter 5
Working with components 5-1
Setting component properties . . . . . . . . . . 5-2
Setting properties at design time . . . . . . . 5-2
Using property editors . . . . . . . . . . . 5-2
Setting properties at runtime . . . . . . . . . 5-3
Calling methods . . . . . . . . . . . . . . . . . . 5-3
Working with events and event
handlers . . . . . . . . . . . . . . . . . . . . . . 5-3
Generating a new event handler . . . . . . . 5-4
Generating a handler for a component’s
default event . . . . . . . . . . . . . . . . . 5-4
Locating event handlers . . . . . . . . . . . . 5-4
Associating an event with an existing
event handler . . . . . . . . . . . . . . . . . 5-4
Using the Sender parameter . . . . . . . . 5-5
Displaying and coding shared
events. . . . . . . . . . . . . . . . . . . . 5-5
ii
Chapter 7
Building applications, components,
and libraries 7-1
Creating applications . . . . . . . . . . . . . . . 7-1
GUI applications . . . . . . . . . . . . . . . . 7-1
User interface models . . . . . . . . . . . 7-2
SDI applications. . . . . . . . . . . . . . . 7-2
MDI applications . . . . . . . . . . . . . . 7-2
Setting IDE, project, and compilation
options . . . . . . . . . . . . . . . . . . . 7-3
Programming templates . . . . . . . . . . . . 7-3
Console applications . . . . . . . . . . . . . . 7-4
Using the VCL and CLX in console
applications . . . . . . . . . . . . . . . . 7-4
Service applications . . . . . . . . . . . . . . 7-4
Service threads . . . . . . . . . . . . . . . 7-7
Service name properties . . . . . . . . . . 7-8
Debugging service applications . . . . . . 7-9
Creating packages and DLLs . . . . . . . . . . . 7-10
When to use packages and DLLs . . . . . . . 7-11
Using DLLs in C++Builder . . . . . . . . . . . . 7-11
Creating DLLs in C++Builder . . . . . . . . . . 7-11
Creating DLLs containing VCL and CLX
components . . . . . . . . . . . . . . . . . . . . 7-12
Linking DLLs . . . . . . . . . . . . . . . . . . . . 7-15
Writing database applications . . . . . . . . . . 7-15
Distributing database applications . . . . . . 7-16
Creating Web server applications . . . . . . . . 7-16
Using Web Broker . . . . . . . . . . . . . . . 7-17
Creating WebSnap applications. . . . . . . . 7-18
Using InternetExpress . . . . . . . . . . . . . 7-18
Creating Web Services applications . . . . . 7-18
Writing applications using COM. . . . . . . . . 7-19
Using COM and DCOM . . . . . . . . . . . . 7-19
Using MTS and COM+ . . . . . . . . . . . . 7-19
Using data modules . . . . . . . . . . . . . . . . 7-20
Creating and editing standard
data modules . . . . . . . . . . . . . . . . . 7-20
Naming a data module and its
unit file . . . . . . . . . . . . . . . . . . . 7-21
Placing and naming components . . . . . 7-22
Using component properties and
events in a data module . . . . . . . . . 7-22
Creating business rules in a data
module . . . . . . . . . . . . . . . . . . . 7-23
Accessing a data module from a form . . . . 7-23
Adding a remote data module to an
application server project . . . . . . . . . . 7-23
Using the Object Repository . . . . . . . . . . . 7-24
Sharing items within a project . . . . . . . . 7-24
Adding items to the Object Repository . . . 7-24
Sharing objects in a team
environment . . . . . . . . . . . . . . . . . 7-24
Using an Object Repository item in
a project . . . . . . . . . . . . . . . . . . . . 7-25
Copying an item . . . . . . . . . . . . . . 7-25
Inheriting an item . . . . . . . . . . . . . 7-25
Using an item. . . . . . . . . . . . . . . . 7-25
Using project templates. . . . . . . . . . . . 7-25
Modifying shared items . . . . . . . . . . . 7-26
Specifying a default project, new form,
and main form . . . . . . . . . . . . . . . . 7-26
Enabling Help in applications . . . . . . . . . . 7-26
Help system interfaces . . . . . . . . . . . . 7-27
Implementing ICustomHelpViewer. . . . . 7-28
Communicating with the Help
Manager . . . . . . . . . . . . . . . . . . . 7-28
Asking the Help Manager for
information. . . . . . . . . . . . . . . . . . 7-28
Displaying keyword-based Help . . . . . . 7-29
Displaying tables of contents. . . . . . . . . 7-30
Implementing IExtendedHelp
Viewer . . . . . . . . . . . . . . . . . . . . 7-30
Implementing IHelpSelector . . . . . . . . . 7-31
Registering Help system objects . . . . . . . 7-32
Registering Help viewers . . . . . . . . . 7-32
Registering Help selectors . . . . . . . . 7-32
Using Help in a VCL Application . . . . . . . . 7-33
How TApplication processes VCL
Help . . . . . . . . . . . . . . . . . . . . . . 7-33
How VCL controls process Help. . . . . . . 7-33
Using Help in a CLX Application . . . . . . . . 7-34
How TApplication processes CLX
Help . . . . . . . . . . . . . . . . . . . . . . 7-34
How CLX controls process Help. . . . . . . 7-34
Calling a Help system directly . . . . . . . . . 7-35
Using IHelpSystem . . . . . . . . . . . . . . . . 7-35
Customizing the IDE Help system . . . . . . . 7-35
Chapter 8
Developing the application user
interface 8-1
Controlling application behavior . . . . . . . . . 8-1
Working at the application level . . . . . . . . 8-2
Handling the screen . . . . . . . . . . . . . . . 8-2
Setting up forms. . . . . . . . . . . . . . . . . . . 8-2
Using the main form . . . . . . . . . . . . . . 8-2
Hiding the main form. . . . . . . . . . . . . . 8-3
iii
Zgłoś jeśli naruszono regulamin