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

delphi 6 - developer's guide

1,1K 24,4K 0

Đ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

Định dạng
Số trang 1.140
Dung lượng 13,97 MB

Nội dung

Developer’s Guide Borland Software Corporation 100 Enterprise Way, Scotts Valley, CA 95066-3249 Borland ® Delphi6 for Windows 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 6 License Statement and Limited Warranty. 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. C OPYRIGHT © 1983, 2001 Borland Software Corporation. All rights reserved. All Borland brand and product names are trademarks or registered trademarks of Borland Software Corporation. Other brand and product names are trademarks or registered trademarks of their respective holders. Printed in the U.S.A. HDE1350WW21001 1E0R0501 0102030405-9 8 7654321 D3 iii 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 Part I Programming with Delphi Chapter 2 Developing applications with Delphi 2-1 Integrated development environment . . . . . . 2-1 Designing applications . . . . . . . . . . . . . . 2-2 Developing applications . . . . . . . . . . . . . 2-3 Creating projects . . . . . . . . . . . . . . . . 2-3 Editing code. . . . . . . . . . . . . . . . . . . 2-4 Compiling applications . . . . . . . . . . . . 2-4 Debugging applications . . . . . . . . . . . . 2-5 Deploying applications . . . . . . . . . . . . 2-5 Chapter 3 Using the component libraries 3-1 Understanding the component 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-4 Object Pascal and the class libraries . . . . . . . 3-4 Using the object model . . . . . . . . . . . . 3-4 What is an object?. . . . . . . . . . . . . . 3-5 Examining a Delphi object . . . . . . . . . 3-5 Changing the name of a component . . . 3-7 Inheriting data and code from an object . . . 3-8 Scope and qualifiers . . . . . . . . . . . . . . 3-8 Private, protected, public, and published declarations . . . . . . . . . . . . . . . . 3-9 Using object variables . . . . . . . . . . . . .3-10 Creating, instantiating, and destroying objects . . . . . . . . . . . . . . . . . . . . . 3-11 Components and ownership . . . . . . . . . 3-11 Objects, components, and controls. . . . . . . .3-12 TObject branch . . . . . . . . . . . . . . . . .3-14 TPersistent branch. . . . . . . . . . . . . . . 3-14 TComponent branch . . . . . . . . . . . . . 3-15 TControl branch . . . . . . . . . . . . . . . . 3-16 TWinControl/TWidgetControl branch . . . 3-17 Properties common to TControl . . . . . . . 3-18 Action properties . . . . . . . . . . . . . 3-18 Position, size, and alignment properties . . . . . . . . . . . . . . . . . 3-19 Display properties . . . . . . . . . . . . . 3-19 Parent properties. . . . . . . . . . . . . . 3-19 A navigation property. . . . . . . . . . . 3-19 Drag-and-drop properties . . . . . . . . 3-20 Drag-and-dock properties (VCL only) . . . . . . . . . . . . . . . . 3-20 Standard events common to TControl . . . 3-20 Properties common to TWinControl and TWidgetControl . . . . . . . . . . . . . . . 3-21 General information properties . . . . . 3-21 Border style display properties. . . . . . 3-22 Navigation properties . . . . . . . . . . . 3-22 Drag-and-dock properties (VCL only) . . . . . . . . . . . . . . . . 3-22 Events common to TWinControl and TWidgetControl . . . . . . . . . . . . . . . 3-22 Creating the application user interface . . . 3-23 Using Delphi components . . . . . . . . . . 3-23 Setting component properties . . . . . . . . 3-24 Using the Object Inspector . . . . . . . . 3-24 Using property editors . . . . . . . . . . 3-25 Setting properties at runtime . . . . . . . 3-25 Calling methods . . . . . . . . . . . . . . . . 3-25 Working with events and event handlers. . . . . . . . . . . . . . . . . . . . 3-25 Generating a new event handler . . . . . 3-26 Generating a handler for a component’s default event . . . . . . . . . . . . . . . 3-26 Locating event handlers. . . . . . . . . . 3-26 Associating an event with an existing event handler . . . . . . . . . . . . . . . 3-27 Associating menu events with event handlers . . . . . . . . . . . . . . . . . . 3-28 Deleting event handlers. . . . . . . . . . 3-28 VCL and CLX components . . . . . . . . . . . 3-28 Adding custom components to the Component palette . . . . . . . . . . . . . 3-30 Text controls . . . . . . . . . . . . . . . . . . 3-31 Text control properties. . . . . . . . . . . 3-31 Contents iv Properties of memo and rich text controls. . . . . . . . . . . . . . . . . . .3-31 Rich text controls (VCL only) . . . . . . . 3-32 Specialized input controls . . . . . . . . . . .3-32 Scroll bars . . . . . . . . . . . . . . . . . .3-32 Track bars . . . . . . . . . . . . . . . . . .3-33 Up-down controls (VCL only). . . . . . . 3-33 Spin edit controls (CLX only) . . . . . . .3-33 Hot key controls (VCL only). . . . . . . .3-33 Splitter controls . . . . . . . . . . . . . . .3-34 Buttons and similar controls . . . . . . . . .3-34 Button controls . . . . . . . . . . . . . . . 3-34 Bitmap buttons . . . . . . . . . . . . . . . 3-35 Speed buttons . . . . . . . . . . . . . . . . 3-35 Check boxes . . . . . . . . . . . . . . . . .3-35 Radio buttons . . . . . . . . . . . . . . . .3-35 Toolbars . . . . . . . . . . . . . . . . . . .3-36 Cool bars (VCL only) . . . . . . . . . . . .3-36 Handling lists . . . . . . . . . . . . . . . . . .3-36 List boxes and check-list boxes . . . . . . 3-37 Combo boxes . . . . . . . . . . . . . . . .3-37 Tree views . . . . . . . . . . . . . . . . . .3-38 List views . . . . . . . . . . . . . . . . . .3-38 Date-time pickers and month calendars (VCL only) . . . . . . . . . . .3-39 Grouping components . . . . . . . . . . . . . 3-39 Group boxes and radio groups . . . . . .3-39 Panels . . . . . . . . . . . . . . . . . . . .3-39 Scroll boxes . . . . . . . . . . . . . . . . .3-40 Tab controls . . . . . . . . . . . . . . . . .3-40 Page controls . . . . . . . . . . . . . . . .3-40 Header controls . . . . . . . . . . . . . . . 3-41 Providing visual feedback. . . . . . . . . . .3-41 Labels and static text components . . . . 3-41 Status bars . . . . . . . . . . . . . . . . . . 3-42 Progress bars . . . . . . . . . . . . . . . .3-42 Help and hint properties . . . . . . . . . . 3-42 Grids . . . . . . . . . . . . . . . . . . . . . . .3-43 Draw grids. . . . . . . . . . . . . . . . . .3-43 String grids . . . . . . . . . . . . . . . . .3-43 Value list editors (VCL only) . . . . . . . . .3-43 Displaying graphics . . . . . . . . . . . . . .3-44 Images . . . . . . . . . . . . . . . . . . . .3-44 Shapes . . . . . . . . . . . . . . . . . . . .3-44 Bevels . . . . . . . . . . . . . . . . . . . .3-45 Paint boxes. . . . . . . . . . . . . . . . . .3-45 Animation control (VCL only). . . . . . .3-45 Developing dialog boxes . . . . . . . . . . .3-45 Using open dialog boxes . . . . . . . . . . 3-46 Using helper objects . . . . . . . . . . . . . . . 3-46 Working with lists . . . . . . . . . . . . . . . 3-47 Working with string lists . . . . . . . . . . . 3-47 Loading and saving string lists. . . . . . 3-48 Creating a new string list . . . . . . . . . 3-48 Manipulating strings in a list . . . . . . . 3-50 Associating objects with a string list. . . 3-52 Windows registry and INI files . . . . . . . 3-52 Using TIniFile (VCL only) . . . . . . . . 3-52 Using TRegistry . . . . . . . . . . . . . . 3-53 Using TRegIniFile . . . . . . . . . . . . . 3-53 Creating drawing spaces . . . . . . . . . . . 3-54 Printing . . . . . . . . . . . . . . . . . . . . . 3-54 Using streams . . . . . . . . . . . . . . . . . 3-55 Chapter 4 Common programming tasks 4-1 Understanding classes . . . . . . . . . . . . . . . 4-1 Defining classes . . . . . . . . . . . . . . . . . . . 4-2 Handling exceptions . . . . . . . . . . . . . . . . 4-4 Protecting blocks of code . . . . . . . . . . . . 4-4 Responding to exceptions. . . . . . . . . . 4-5 Exceptions and the flow of control. . . . . 4-6 Nesting exception responses . . . . . . . . 4-6 Protecting resource allocations. . . . . . . . . 4-7 What kind of resources need protection? . . . . . . . . . . . . . . . . . 4-7 Creating a resource protection block. . . . 4-8 Handling RTL exceptions. . . . . . . . . . . . 4-9 What are RTL exceptions? . . . . . . . . . 4-9 Creating an exception handler . . . . . . 4-10 Exception handling statements. . . . . . 4-11 Using the exception instance . . . . . . . 4-11 Scope of exception handlers . . . . . . . 4-12 Providing default exception handlers . . . . . . . . . . . . . . . . . . 4-12 Handling classes of exceptions . . . . . . 4-13 Reraising the exception . . . . . . . . . . 4-13 Handling component exceptions . . . . . . 4-14 Exception handling with external sources . . . . . . . . . . . . . . . . . . . . 4-15 Silent exceptions. . . . . . . . . . . . . . . . 4-15 Defining your own exceptions. . . . . . . . 4-16 Declaring an exception object type. . . . 4-16 Raising an exception. . . . . . . . . . . . 4-17 Using interfaces . . . . . . . . . . . . . . . . . . 4-17 Interfaces as a language feature . . . . . . . 4-18 Implementing interfaces across the hierarchy . . . . . . . . . . . . . . . 4-18 v Using interfaces with procedures . . . . .4-20 Implementing IInterface . . . . . . . . . . . .4-20 TInterfacedObject . . . . . . . . . . . . . . .4-21 Using the as operator . . . . . . . . . . . . .4-21 Reusing code and delegation . . . . . . . . . 4-22 Using implements for delegation . . . . .4-22 Aggregation . . . . . . . . . . . . . . . . . 4-23 Memory management of interface objects . . . . . . . . . . . . . . . . . . . . .4-24 Using reference counting . . . . . . . . .4-24 Not using reference counting . . . . . . .4-25 Using interfaces in distributed applications (VCL only) . . . . . . . . . . .4-26 Defining custom variants . . . . . . . . . . . . .4-27 Storing a custom variant type’s data . . . . . 4-28 Creating a class to enable the custom variant type . . . . . . . . . . . . . . . . . .4-28 Enabling casting . . . . . . . . . . . . . .4-29 Implementing binary operations . . . . . 4-30 Implementing comparison operations . . 4-32 Implementing unary operations . . . . . 4-34 Copying and clearing custom variants. . . . . . . . . . . . . . . . . . .4-34 Loading and saving custom variant values. . . . . . . . . . . . . . . . . . . . 4-35 Using the TCustomVariantType descendant . . . . . . . . . . . . . . . . .4-36 Writing utilities to work with a custom variant type . . . . . . . . . . . . . . . . . .4-36 Supporting properties and methods in custom variants . . . . . . . . . . . . . . . . 4-37 Using TInvokeableVariantType . . . . . .4-37 Using TPublishableVariantType. . . . . .4-39 Working with strings . . . . . . . . . . . . . . . 4-39 Character types . . . . . . . . . . . . . . . . .4-39 String types . . . . . . . . . . . . . . . . . . .4-40 Short strings . . . . . . . . . . . . . . . . .4-40 Long strings . . . . . . . . . . . . . . . . .4-41 WideString. . . . . . . . . . . . . . . . . . 4-41 PChar types . . . . . . . . . . . . . . . . .4-42 OpenString . . . . . . . . . . . . . . . . .4-42 Runtime library string handling routines . .4-42 Wide character routines . . . . . . . . . .4-43 Commonly used long string routines. . .4-43 Declaring and initializing strings. . . . . . .4-46 Mixing and converting string types . . . . .4-47 String to PChar conversions. . . . . . . . . .4-47 String dependencies . . . . . . . . . . . . 4-47 Returning a PChar local variable . . . . .4-48 Passing a local variable as a PChar . . . 4-48 Compiler directives for strings. . . . . . . . 4-49 Strings and characters: related topics . . . . 4-50 Working with files . . . . . . . . . . . . . . . . 4-50 Manipulating files . . . . . . . . . . . . . . . 4-50 Deleting a file. . . . . . . . . . . . . . . . 4-50 Finding a file . . . . . . . . . . . . . . . . 4-51 Renaming a file. . . . . . . . . . . . . . . 4-52 File date-time routines . . . . . . . . . . 4-52 Copying a file . . . . . . . . . . . . . . . 4-53 File types with file I/O . . . . . . . . . . . . 4-53 Using file streams . . . . . . . . . . . . . . . 4-54 Creating and opening files . . . . . . . . 4-54 Using the file handle . . . . . . . . . . . 4-55 Reading and writing to files . . . . . . . 4-55 Reading and writing strings . . . . . . . 4-56 Seeking a file . . . . . . . . . . . . . . . . 4-56 File position and size . . . . . . . . . . . 4-57 Copying. . . . . . . . . . . . . . . . . . . 4-57 Converting measurements . . . . . . . . . . . . 4-58 Performing conversions . . . . . . . . . . . 4-58 Performing simple conversions . . . . . 4-58 Performing complex conversions . . . . 4-58 Adding new measurement types . . . . . . 4-59 Creating a simple conversion family and adding units . . . . . . . . . . . . . 4-59 Using a conversion function . . . . . . . 4-60 Using a class to manage conversions . . . . . . . . . . . . . . . . 4-62 Defining data types . . . . . . . . . . . . . . . . 4-64 Chapter 5 Building applications, components, and libraries 5-1 Creating applications . . . . . . . . . . . . . . . . 5-1 GUI applications. . . . . . . . . . . . . . . . . 5-1 User interface models . . . . . . . . . . . . 5-2 SDI applications . . . . . . . . . . . . . . . 5-2 MDI applications. . . . . . . . . . . . . . . 5-2 Setting IDE, project, and compilation options . . . . . . . . . . . . . . . . . . . 5-3 Programming templates . . . . . . . . . . . . 5-3 Console applications . . . . . . . . . . . . . . 5-3 Service applications . . . . . . . . . . . . . . . 5-4 Service threads . . . . . . . . . . . . . . . . 5-6 Service name properties. . . . . . . . . . . 5-7 Debugging services . . . . . . . . . . . . . 5-8 Creating packages and DLLs . . . . . . . . . . . 5-9 When to use packages and DLLs . . . . . . . 5-9 vi Writing database applications . . . . . . . . . .5-10 Distributing database applications . . . . . . 5-11 Creating Web server applications . . . . . . . . 5-11 Using Web Broker . . . . . . . . . . . . . . . 5-11 Creating WebSnap applications. . . . . . . . 5-13 Using InternetExpress . . . . . . . . . . . . .5-13 Creating Web Services applications . . . . . 5-13 Writing applications using COM. . . . . . . . .5-14 Using COM and DCOM . . . . . . . . . . . . 5-14 Using MTS and COM+ . . . . . . . . . . . .5-14 Using data modules . . . . . . . . . . . . . . . . 5-15 Creating and editing standard data modules . . . . . . . . . . . . . . . . . . . .5-15 Naming a data module and its unit file. . . . . . . . . . . . . . . . . . . . . .5-16 Placing and naming components . . . . .5-17 Using component properties and events in a data module . . . . . . . . .5-17 Creating business rules in a data module . . . . . . . . . . . . . . . . . . .5-18 Accessing a data module from a form . . . . 5-18 Adding a remote data module to an application server project . . . . . . . . . .5-19 Using the Object Repository . . . . . . . . . . .5-19 Sharing items within a project . . . . . . . .5-19 Adding items to the Object Repository . . .5-19 Sharing objects in a team environment . . .5-20 Using an Object Repository item in a project . . . . . . . . . . . . . . . . . . . .5-20 Copying an item . . . . . . . . . . . . . .5-20 Inheriting an item. . . . . . . . . . . . . .5-20 Using an item . . . . . . . . . . . . . . . .5-21 Using project templates . . . . . . . . . . . . 5-21 Modifying shared items . . . . . . . . . . . .5-21 Specifying a default project, new form, and main form . . . . . . . . . . . . . . . .5-21 Enabling Help in applications . . . . . . . . . .5-22 Help system interfaces. . . . . . . . . . . . . 5-22 Implementing ICustomHelpViewer . . . . . 5-23 Communicating with the Help Manager . . . . . . . . . . . . . . . . . . . . 5-23 Asking the Help Manager for information . . . . . . . . . . . . . . . . . .5-24 Displaying keyword-based Help . . . . . . . 5-24 Displaying tables of contents . . . . . . . . . 5-25 Implementing IExtendedHelpViewer . . . . 5-26 Implementing IHelpSelector . . . . . . . . .5-26 Registering Help system objects . . . . . . . 5-27 Registering Help viewers . . . . . . . . . 5-27 Registering Help selectors . . . . . . . . 5-27 Using Help in a VCL Application. . . . . . . . 5-28 How TApplication processes VCL Help . . . . . . . . . . . . . . . . . . . . . . 5-28 How VCL controls process Help. . . . . . . 5-28 Using Help in a CLX Application . . . . . . . . 5-29 How TApplication processes CLX Help . . . . . . . . . . . . . . . . . . . . . . 5-29 How CLX controls process Help. . . . . . . 5-29 Calling a Help system directly . . . . . . . . . 5-30 Using IHelpSystem . . . . . . . . . . . . . . . . 5-30 Customizing the IDE Help system . . . . . . . 5-30 Chapter 6 Developing the application user interface 6-1 Controlling application behavior . . . . . . . . . 6-1 Using the main form . . . . . . . . . . . . . . 6-1 Adding forms . . . . . . . . . . . . . . . . . . 6-2 Linking forms . . . . . . . . . . . . . . . . 6-2 Avoiding circular unit references. . . . . . 6-2 Hiding the main form. . . . . . . . . . . . . . 6-3 Working at the application level . . . . . . . . 6-3 Handling the screen . . . . . . . . . . . . . . . 6-3 Managing layout . . . . . . . . . . . . . . . . 6-4 Responding to event notification . . . . . . . . . 6-5 Using forms . . . . . . . . . . . . . . . . . . . . . 6-5 Controlling when forms reside in memory. . . . . . . . . . . . . . . . . . . . . 6-6 Displaying an auto-created form. . . . . . 6-6 Creating forms dynamically . . . . . . . . 6-6 Creating modeless forms such as windows . . . . . . . . . . . . . . . . . . 6-7 Using a local variable to create a form instance . . . . . . . . . . . . . . . . . . . 6-7 Passing additional arguments to forms . . . . 6-8 Retrieving data from forms. . . . . . . . . . . 6-9 Retrieving data from modeless forms . . . 6-9 Retrieving data from modal forms. . . . 6-10 Reusing components and groups of components . . . . . . . . . . . . . . . . . . . 6-12 Creating and using component templates . . . 6-13 Working with frames . . . . . . . . . . . . . . . 6-13 Creating frames . . . . . . . . . . . . . . . . 6-14 Adding frames to the component palette. . . . . . . . . . . . . . . . . . . . . 6-14 Using and modifying frames. . . . . . . . . 6-14 Sharing frames. . . . . . . . . . . . . . . . . 6-15 vii Organizing actions for toolbars and menus . . . . . . . . . . . . . . . . . . . . . . . 6-16 What is an action? . . . . . . . . . . . . . . . 6-17 Setting up action bands . . . . . . . . . . . .6-18 Creating toolbars and menus . . . . . . . . .6-18 Adding color, patterns, or pictures to menus, buttons, and toolbars . . . . . .6-20 Adding icons to menus and toolbars . . . 6-21 Creating toolbars and menus that users can customize. . . . . . . . . . . .6-21 Hiding unused items and categories in action bands . . . . . . . . . . . . . .6-22 Using action lists . . . . . . . . . . . . . . . . . .6-23 Setting up action lists . . . . . . . . . . . . .6-23 What happens when an action fires . . . . . 6-24 Responding with events . . . . . . . . . .6-24 How actions find their targets. . . . . . . 6-26 Updating actions . . . . . . . . . . . . . . . .6-26 Predefined action classes . . . . . . . . . . .6-26 Writing action components . . . . . . . . . .6-27 Registering actions . . . . . . . . . . . . . . .6-28 Creating and managing menus. . . . . . . . . . 6-29 Opening the Menu Designer . . . . . . . . . 6-29 Building menus. . . . . . . . . . . . . . . . .6-31 Naming menus . . . . . . . . . . . . . . . 6-31 Naming the menu items . . . . . . . . . .6-31 Adding, inserting, and deleting menu items . . . . . . . . . . . . . . . .6-32 Adding separator bars . . . . . . . . . . . 6-32 Specifying accelerator keys and keyboard shortcuts . . . . . . . . . . . .6-33 Creating submenus. . . . . . . . . . . . . . . 6-33 Creating submenus by demoting existing menus . . . . . . . . . . . . . .6-34 Moving menu items . . . . . . . . . . . .6-34 Adding images to menu items . . . . . .6-35 Viewing the menu . . . . . . . . . . . . .6-35 Editing menu items in the Object Inspector. . . . . . . . . . . . . . . . . . . .6-35 Using the Menu Designer context menu . . . . . . . . . . . . . . . . . . . . . . 6-36 Commands on the context menu . . . . . 6-36 Switching between menus at design time . . . . . . . . . . . . . . . . . . . . . 6-37 Using menu templates . . . . . . . . . . . . .6-37 Saving a menu as a template . . . . . . . . .6-38 Naming conventions for template menu items and event handlers . . . . .6-39 Manipulating menu items at runtime . . . .6-40 Merging menus . . . . . . . . . . . . . . . . 6-40 Specifying the active menu: Menu property . . . . . . . . . . . . . . . . . . 6-40 Determining the order of merged menu items: GroupIndex property . . . . . . 6-40 Importing resource files . . . . . . . . . . . 6-41 Designing toolbars and cool bars . . . . . . . . 6-41 Adding a toolbar using a panel component . . . . . . . . . . . . . . . . . . 6-42 Adding a speed button to a panel . . . . 6-43 Assigning a speed button’s glyph . . . . 6-43 Setting the initial condition of a speed button . . . . . . . . . . . . . . . 6-43 Creating a group of speed buttons. . . . 6-44 Allowing toggle buttons . . . . . . . . . 6-44 Adding a toolbar using the toolbar component . . . . . . . . . . . . . . . . . . 6-44 Adding a tool button . . . . . . . . . . . 6-45 Assigning images to tool buttons . . . . 6-45 Setting tool button appearance and initial conditions . . . . . . . . . . . . . 6-46 Creating groups of tool buttons . . . . . 6-46 Allowing toggled tool buttons . . . . . . 6-46 Adding a cool bar component . . . . . . . . 6-47 Setting the appearance of the cool bar . . . . . . . . . . . . . . . . . . 6-47 Responding to clicks . . . . . . . . . . . . . 6-48 Assigning a menu to a tool button . . . . 6-48 Adding hidden toolbars . . . . . . . . . . . 6-48 Hiding and showing toolbars . . . . . . . . 6-48 Demo programs . . . . . . . . . . . . . . . . 6-49 Chapter 7 Working with controls 7-1 Implementing drag-and-drop in controls . . . . 7-1 Starting a drag operation . . . . . . . . . . . . 7-1 Accepting dragged items . . . . . . . . . . . . 7-2 Dropping items . . . . . . . . . . . . . . . . . 7-2 Ending a drag operation . . . . . . . . . . . . 7-3 Customizing drag and drop with a drag object . . . . . . . . . . . . . . . . . . . 7-3 Changing the drag mouse pointer. . . . . . . 7-4 Implementing drag-and-dock in controls . . . . 7-4 Making a windowed control a docking site. . . . . . . . . . . . . . . . . . . . . . . . 7-4 Making a control a dockable child. . . . . . . 7-4 Controlling how child controls are docked . . . . . . . . . . . . . . . . . . . . . 7-5 viii Controlling how child controls are undocked . . . . . . . . . . . . . . . . . . . 7-6 Controlling how child controls respond to drag-and-dock operations . . . . . . . . 7-6 Working with text in controls. . . . . . . . . . . 7-6 Setting text alignment . . . . . . . . . . . . . 7-7 Adding scroll bars at runtime . . . . . . . . . 7-7 Adding the clipboard object. . . . . . . . . . 7-8 Selecting text . . . . . . . . . . . . . . . . . . 7-8 Selecting all text . . . . . . . . . . . . . . . . 7-9 Cutting, copying, and pasting text . . . . . . 7-9 Deleting selected text . . . . . . . . . . . . . 7-9 Disabling menu items . . . . . . . . . . . . .7-10 Providing a pop-up menu . . . . . . . . . . . 7-10 Handling the OnPopup event. . . . . . . . . 7-11 Adding graphics to controls . . . . . . . . . . . 7-11 Indicating that a control is owner-drawn . . . . . . . . . . . . . . . . .7-12 Adding graphical objects to a string list . . .7-12 Adding images to an application . . . . .7-13 Adding images to a string list . . . . . . .7-13 Drawing owner-drawn items . . . . . . .7-13 Sizing owner-draw items . . . . . . . . . . .7-14 Drawing owner-draw items. . . . . . . . . .7-15 Chapter 8 Working with graphics and multimedia 8-1 Overview of graphics programming. . . . . . . 8-1 Refreshing the screen . . . . . . . . . . . . . 8-2 Types of graphic objects . . . . . . . . . . . . 8-3 Common properties and methods of Canvas . . . . . . . . . . . . . . . . . . . . . 8-4 Using the properties of the Canvas object . . . . . . . . . . . . . . . . . . . . . 8-5 Using pens. . . . . . . . . . . . . . . . . . 8-5 Using brushes . . . . . . . . . . . . . . . . 8-8 Reading and setting pixels. . . . . . . . . 8-9 Using Canvas methods to draw graphic objects . . . . . . . . . . . . . . . . . . . . . 8-9 Drawing lines and polylines. . . . . . . .8-10 Drawing shapes . . . . . . . . . . . . . . . 8-11 Handling multiple drawing objects in your application . . . . . . . . . . . . . . .8-12 Keeping track of which drawing tool to use . . . . . . . . . . . . . . . . . . . . 8-12 Changing the tool with speed buttons . .8-13 Using drawing tools . . . . . . . . . . . . 8-13 Drawing on a graphic . . . . . . . . . . . . .8-16 Making scrollable graphics . . . . . . . . 8-16 Adding an image control . . . . . . . . . 8-17 Loading and saving graphics files. . . . . . 8-18 Loading a picture from a file . . . . . . . 8-19 Saving a picture to a file. . . . . . . . . . 8-19 Replacing the picture . . . . . . . . . . . 8-20 Using the clipboard with graphics . . . . . 8-21 Copying graphics to the clipboard. . . . 8-21 Cutting graphics to the clipboard . . . . 8-21 Pasting graphics from the clipboard . . . 8-22 Rubber banding example. . . . . . . . . . . 8-23 Responding to the mouse . . . . . . . . . 8-23 Responding to a mouse-down action . . 8-24 Adding a field to a form object to track mouse actions . . . . . . . . . . . . . . 8-26 Refining line drawing . . . . . . . . . . . 8-27 Working with multimedia . . . . . . . . . . . . 8-28 Adding silent video clips to an application . . . . . . . . . . . . . . . . . . 8-29 Example of adding silent video clips . . 8-30 Adding audio and/or video clips to an application . . . . . . . . . . . . . . . . . . 8-30 Example of adding audio and/or video clips (VCL only) . . . . . . . . . . . . . 8-32 Chapter 9 Writing multi-threaded applications 9-1 Defining thread objects. . . . . . . . . . . . . . . 9-1 Initializing the thread . . . . . . . . . . . . . . 9-2 Assigning a default priority . . . . . . . . 9-2 Indicating when threads are freed . . . . . 9-3 Writing the thread function . . . . . . . . . . 9-4 Using the main VCL/CLX thread . . . . . 9-4 Using thread-local variables . . . . . . . . 9-5 Checking for termination by other threads . . . . . . . . . . . . . . . . . . . 9-5 Handling exceptions in the thread function . . . . . . . . . . . . . . . . . . . 9-6 Writing clean-up code. . . . . . . . . . . . . . 9-6 Coordinating threads . . . . . . . . . . . . . . . . 9-7 Avoiding simultaneous access . . . . . . . . . 9-7 Locking objects. . . . . . . . . . . . . . . . 9-7 Using critical sections . . . . . . . . . . . . 9-7 Using the multi-read exclusive-write synchronizer . . . . . . . . . . . . . . . . 9-8 Other techniques for sharing memory. . . 9-8 Waiting for other threads . . . . . . . . . . . . 9-9 Waiting for a thread to finish executing . . . . . . . . . . . . . . . . . . 9-9 ix Waiting for a task to be completed . . . . 9-9 Executing thread objects . . . . . . . . . . . . . 9-10 Overriding the default priority . . . . . . . . 9-11 Starting and stopping threads . . . . . . . . 9-11 Debugging multi-threaded applications . . . .9-12 Chapter 10 Using CLX for cross-platform development 10-1 Creating cross-platform applications . . . . . . 10-1 Porting VCL applications to CLX . . . . . . . .10-2 Porting techniques . . . . . . . . . . . . . . .10-3 Platform-specific ports . . . . . . . . . . .10-3 Cross-platform ports . . . . . . . . . . . . 10-3 Windows emulation ports . . . . . . . . .10-3 Porting your application. . . . . . . . . . . .10-4 CLX versus VCL . . . . . . . . . . . . . . . .10-5 What CLX does differently . . . . . . . . . . 10-6 Look and feel . . . . . . . . . . . . . . . .10-6 Styles . . . . . . . . . . . . . . . . . . . . .10-6 Variants . . . . . . . . . . . . . . . . . . . 10-7 Registry . . . . . . . . . . . . . . . . . . . 10-7 Other differences . . . . . . . . . . . . . . 10-7 Missing in CLX . . . . . . . . . . . . . . . . .10-8 Features that will not port . . . . . . . . . . .10-8 CLX and VCL unit comparison . . . . . . . .10-9 Differences in CLX object constructors . . . . . . . . . . . . . . . . . 10-13 Sharing source files between Windows and Linux . . . . . . . . . . . . 10-13 Environmental differences between Windows and Linux . . . . . . . . . . . . 10-14 Directory structure on Linux . . . . . . . . 10-16 Writing portable code . . . . . . . . . . . . 10-17 Using conditional directives . . . . . . . 10-18 Terminating conditional directives . . . 10-19 Emitting messages . . . . . . . . . . . . 10-20 Including inline assembler code. . . . . 10-20 Messages and system events . . . . . . . . 10-21 Programming differences on Linux . . . . 10-22 Cross-platform database applications . . . . . 10-23 dbExpress differences . . . . . . . . . . . . 10-23 Component-level differences . . . . . . . . 10-24 User interface-level differences . . . . . . . 10-25 Porting database applications to Linux . . . . . . . . . . . . . . . . . . . . . 10-25 Updating data in dbExpress applications . . . . . . . . . . . . . . . . . 10-27 Cross-platform Internet applications . . . . . 10-29 Porting Internet applications to Linux . . 10-29 Chapter 11 Working with packages and components 11-1 Why use packages? . . . . . . . . . . . . . . . . 11-2 Packages and standard DLLs . . . . . . . . 11-2 Runtime packages . . . . . . . . . . . . . . . . 11-2 Using packages in an application . . . . . . 11-3 Dynamically loading packages . . . . . . . 11-4 Deciding which runtime packages to use . . . . . . . . . . . . . . . . . . . . . 11-4 Custom packages . . . . . . . . . . . . . . . 11-4 Design-time packages . . . . . . . . . . . . . . 11-5 Installing component packages . . . . . . . 11-5 Creating and editing packages . . . . . . . . . 11-6 Creating a package . . . . . . . . . . . . . . 11-6 Editing an existing package . . . . . . . . . 11-7 Editing package source files manually . . . 11-8 Understanding the structure of a package . . . . . . . . . . . . . . . . . . . . 11-8 Naming packages . . . . . . . . . . . . . 11-8 Requires clause. . . . . . . . . . . . . . . 11-8 Contains clause. . . . . . . . . . . . . . . 11-9 Compiling packages . . . . . . . . . . . . .11-10 Package-specific compiler directives . . . . . . . . . . . . . . . . .11-10 Using the command-line compiler and linker . . . . . . . . . . . . . . . . .11-12 Package files created by a successful compilation . . . . . . . . . . . . . . . .11-12 Deploying packages . . . . . . . . . . . . . . .11-13 Deploying applications that use packages . . . . . . . . . . . . . . . . . . .11-13 Distributing packages to other developers . . . . . . . . . . . . . . . . . .11-13 Package collection files . . . . . . . . . . . .11-13 Chapter 12 Creating international applications 12-1 Internationalization and localization . . . . . . 12-1 Internationalization . . . . . . . . . . . . . . 12-1 Localization . . . . . . . . . . . . . . . . . . 12-2 Internationalizing applications . . . . . . . . . 12-2 Enabling application code . . . . . . . . . . 12-2 Character sets . . . . . . . . . . . . . . . 12-2 OEM and ANSI character sets . . . . . . 12-3 Multibyte character sets. . . . . . . . . . 12-3 Wide characters . . . . . . . . . . . . . . 12-4 x Including bi-directional functionality in applications . . . . . . . . . . . . . . . 12-4 BiDiMode property . . . . . . . . . . . . .12-6 Locale-specific features. . . . . . . . . . .12-8 Designing the user interface. . . . . . . . . .12-9 Text . . . . . . . . . . . . . . . . . . . . . . 12-9 Graphic images . . . . . . . . . . . . . . . 12-9 Formats and sort order . . . . . . . . . . 12-10 Keyboard mappings . . . . . . . . . . . 12-10 Isolating resources . . . . . . . . . . . . . . 12-10 Creating resource DLLs . . . . . . . . . . . 12-10 Using resource DLLs . . . . . . . . . . . . . 12-12 Dynamic switching of resource DLLs . . . 12-13 Localizing applications . . . . . . . . . . . . . 12-13 Localizing resources . . . . . . . . . . . . . 12-13 Chapter 13 Deploying applications 13-1 Deploying general applications . . . . . . . . .13-1 Using installation programs. . . . . . . . . .13-2 Identifying application files . . . . . . . .13-2 Application files. . . . . . . . . . . . . . . 13-3 Package files . . . . . . . . . . . . . . . . .13-3 Merge modules . . . . . . . . . . . . . . . 13-3 ActiveX controls . . . . . . . . . . . . . .13-5 Helper applications. . . . . . . . . . . . . 13-5 DLL locations . . . . . . . . . . . . . . . .13-5 Deploying CLX applications . . . . . . . . . . . 13-6 Deploying database applications. . . . . . . . . 13-6 Deploying dbExpress database applications . . . . . . . . . . . . . . . . . .13-7 Deploying BDE applications . . . . . . . . .13-8 Borland Database Engine . . . . . . . . .13-8 SQL Links . . . . . . . . . . . . . . . . . . 13-8 Deploying multi-tiered database applications (DataSnap) . . . . . . . . . . .13-9 Deploying Web applications . . . . . . . . . . .13-9 Deployment on Apache . . . . . . . . . . . 13-10 Programming for varying host environments . . . . . . . . . . . . . . . . . . 13-11 Screen resolutions and color depths . . . . 13-11 Considerations when not dynamically resizing . . . . . . . . . . 13-11 Considerations when dynamically resizing forms and controls . . . . . . 13-12 Accommodating varying color depths . . . . . . . . . . . . . . . . . . 13-13 Fonts . . . . . . . . . . . . . . . . . . . . . . 13-13 Operating systems versions . . . . . . . . . 13-14 Software license requirements. . . . . . . . . 13-14 DEPLOY . . . . . . . . . . . . . . . . . . . 13-14 README . . . . . . . . . . . . . . . . . . . 13-15 No-nonsense license agreement . . . . . . 13-15 Third-party product documentation . . . 13-15 Part II Developing database applications Chapter 14 Designing database applications 14-1 Using databases . . . . . . . . . . . . . . . . . . 14-1 Types of databases. . . . . . . . . . . . . . . 14-2 Database security . . . . . . . . . . . . . . . 14-3 Transactions . . . . . . . . . . . . . . . . . . 14-4 Referential integrity, stored procedures, and triggers. . . . . . . . . . . . . . . . . . 14-5 Database architecture. . . . . . . . . . . . . . . 14-5 General structure . . . . . . . . . . . . . . . 14-6 The user interface form . . . . . . . . . . 14-6 The data module . . . . . . . . . . . . . . 14-6 Connecting directly to a database server . . . . . . . . . . . . . . . . . . . . . 14-7 Using a dedicated file on disk . . . . . . . . 14-9 Connecting to another dataset . . . . . . . 14-10 Connecting a client dataset to another dataset in the same application. . . . .14-11 Using a multi-tiered architecture. . . . 14-12 Combining approaches . . . . . . . . . . . 14-14 Designing the user interface . . . . . . . . . . 14-15 Analyzing data . . . . . . . . . . . . . . . 14-15 Writing reports. . . . . . . . . . . . . . . . 14-16 Chapter 15 Using data controls 15-1 Using common data control features . . . . . . 15-2 Associating a data control with a dataset . . . . . . . . . . . . . . . . . . . . 15-3 Changing the associated dataset at runtime . . . . . . . . . . . . . . . . . 15-3 Enabling and disabling the data source . . . . . . . . . . . . . . . . . . . 15-4 Responding to changes mediated by the data source . . . . . . . . . . . . . . 15-4 Editing and updating data . . . . . . . . . . 15-5 Enabling editing in controls on user entry . . . . . . . . . . . . . . . . . . . . 15-5 Editing data in a control. . . . . . . . . . 15-5 [...]... 1 5-8 1 5-9 1 5-9 1 5-1 0 1 5-1 2 1 5-1 3 1 5-1 4 1 5-1 5 1 5-1 5 1 5- 16 1 5- 16 1 5-1 7 1 5-1 8 1 5-1 9 1 5-1 9 1 5-2 0 1 5-2 1 1 5-2 1 1 5-2 1 1 5-2 3 1 5-2 5 1 5-2 5 1 5-2 5 1 5- 26 1 5-2 8 1 5-2 8 1 5-2 9 xi 1 6- 1 1 6- 1 1 6- 2 1 6- 2 1 6- 3 1 6- 3 1 6- 4 1 6- 5 1 6- 6 1 6- 7 1 6- 7 1 6- 7 1 6- 8 1 6- 8 1 6- 8 1 6- 9 1 6- 9 1 6- 9 1 6- 10 1 6- 10 1 6- 10 1 6- 11 1 6- 11 1 6- 11 1 6- 11 1 6- 12 1 6- 12... in-process server Registering an out-of-process server Testing and debugging the application Registering an out-of-process server 3 7-8 Testing and debugging the Active Server Page application 3 7-8 3 6- 2 3 6- 2 3 6- 2 3 6- 4 3 6- 5 3 6- 6 Chapter 38 Creating an ActiveX control 3 6- 7 3 6- 8 3 6- 9 3 6- 9 3 6- 9 3 6- 10 3 6- 10 3 6- 12 3 6- 12 3 6- 13 3 6- 14 3 6- 14 3 6- 15 3 6- 15 3 6- 16 3 6- 16. .. from another table Using TQuery 2 0-1 2 0-1 2 0-2 2 0-3 2 0-4 2 0-4 2 0-4 2 0-5 20 -6 20 -6 2 0-7 2 0-8 2 0-8 xiv 2 0-9 2 0-1 0 2 0-1 1 2 0-1 1 2 0-1 2 2 0-1 2 2 0-1 2 2 0-1 3 2 0-1 3 2 0-1 3 2 0-1 5 2 0- 16 2 0- 16 2 0-1 7 2 0-1 8 2 0-1 9 2 0-2 1 2 0-2 4 2 0-2 4 2 0- 26 2 0-2 7 2 0-2 8 2 0-2 8 2 0-3 0 2 0-3 0 2 0-3 1 2 0-3 2 2 0-3 3 2 0-3 3 2 0-3 5 2 0-3 5 2 0- 36 2 0-3 7 2 0-3 9 Creating SQL statements for update components... Responding to client-generated events Handling server constraints 2 3-1 2 2 3-1 3 2 3-1 3 2 3-1 3 2 3-1 4 2 3-1 4 2 3-1 5 2 3- 16 2 4-2 Chapter 24 2 3-1 0 2 3-1 1 2 3-1 1 2 3-2 8 2 3-2 9 2 3-1 7 2 3-1 8 2 3-1 9 2 3-1 9 2 3-2 0 2 3-2 2 2 3-2 3 2 3-2 4 2 3-2 5 2 3-2 5 2 3- 26 2 4-2 2 4-2 2 4-3 2 4-4 2 4-4 2 4-4 2 4-5 24 -6 2 4-7 2 4-8 2 4-9 2 4-9 2 4-1 1 2 4-1 1 2 4-1 1 2 4-1 2 2 4-1 2 Chapter 25 Creating multi-tiered applications... Converting user-defined nodes Using an XML document as the source for a provider Using an XML document as the client of a provider 2 5-2 4 2 5-2 5 2 5- 26 2 5- 26 2 5-2 7 2 5-2 7 2 5-2 8 2 5-2 8 xvii 2 6- 1 2 6- 1 2 6- 2 2 6- 4 2 6- 4 2 6- 4 2 6- 5 2 6- 6 2 6- 6 2 6- 7 2 6- 7 2 6- 7 2 6- 8 2 6- 9 Fetching an XML document from a provider 2 6- 9 Applying updates... monitor SQL commands 2 1-1 2 1-1 4 2 1-1 5 2 1- 16 2 1-1 7 2 1-1 7 2 1-1 8 2 1-1 8 2 1-1 9 Using unidirectional datasets 2 1-1 2 1-2 Chapter 22 Chapter 21 Working with ADO components 2 2-2 2 2-2 2 2-3 2 2-3 2 2-4 2 2-4 2 2-5 2 2-5 22 -6 22 -6 22 -6 2 2-7 2 2-7 2 2-8 2 2-8 2 2-9 2 2-9 2 2-9 2 2-1 0 2 2-1 0 2 2-1 2 2 2-1 2 2 2-1 2 2 2-1 3 2 2-1 3 2 2-1 7 2 2-1 7 2 2-1 8 Chapter 23 Using client datasets... owner-draw styles Graphic object types Common properties of the Canvas object Common methods of the Canvas object Mouse-event parameters 1-3 3-1 3 3-1 7 3-2 9 3-3 1 3-4 7 4-9 4-4 0 4-4 4 4-4 4 4-4 5 4-4 5 4-4 5 4-4 9 4-5 1 4-5 3 4-5 4 4-5 4 4-5 5 5-9 5-1 0 5-1 2 5- 16 5-2 8 6- 16 6- 22 6- 27 6- 31 6- 36 6- 44... parameters 1 7-1 1 7-2 1 7-2 1 7-3 1 7-3 1 7-4 1 7-5 17 -6 1 7-7 1 7-8 1 7-8 1 7-9 1 7-1 0 1 7-1 1 1 7-1 2 1 7-1 2 1 7-1 2 1 7-1 3 1 7-1 3 1 7-1 3 1 7-1 4 1 7-1 4 Chapter 18 Understanding datasets 1 8-1 Using TDataSet descendants 1 8-2 Determining dataset states 1 8-3 xii 1 8-4 1 8-5 18 -6 18 -6 1 8-7 1 8-7 1 8-7 1 8-8 1 8-9 1 8-9 1 8-9 ... producers Using table producers Specifying the table attributes xviii 28 -6 28 -6 2 8-7 2 8-7 2 8-8 2 8-8 2 8-8 2 8-9 2 8-9 2 8-9 2 8-9 2 8-1 0 2 8-1 0 2 8-1 0 2 8-1 0 2 8-1 1 2 8-1 1 2 8-1 1 2 8-1 2 2 8-1 2 2 8-1 2 2 8-1 2 2 8-1 3 2 8-1 3 2 8-1 3 2 8-1 4 2 8-1 4 2 8-1 5 2 8- 16 2 8-1 7 2 8-1 7 2 8-1 8 2 8-1 8 2 8-1 8 2 8-1 8 Specifying the row attributes Specifying the columns Embedding tables... 15 .6 Grid control events 15.7 Selected database control grid properties 15.8 TDBNavigator buttons 17.1 Database connection components xxvii 8-3 2 9-3 9-1 0 1 0-3 10 -6 1 0-9 1 0-1 0 1 0-1 1 1 0-1 1 1 0-1 4 1 0- 16 1 0-2 1 1 0-2 4 1 0-2 8 1 1-2 1 1-1 0 1 1-1 2 1 1-1 2 1 2-4 1 2-9 1 3-3 1 3-4 1 3-7 1 3-7 1 3-9 1 5-2 1 5-1 9 1 5-2 0 1 5-2 3 1 5-2 4 1 5- 26 1 5-2 7 1 5-2 8 1 7-1 18.1 18.2 . . . 6- 5 Controlling when forms reside in memory. . . . . . . . . . . . . . . . . . . . . 6- 6 Displaying an auto-created form. . . . . . 6- 6 Creating forms dynamically . . . . . . . . 6- 6 Creating. . . . . . . . . . 6- 24 How actions find their targets. . . . . . . 6- 26 Updating actions . . . . . . . . . . . . . . . . 6- 26 Predefined action classes . . . . . . . . . . . 6- 26 Writing action. . . . . . . . . . . . . 6- 46 Creating groups of tool buttons . . . . . 6- 46 Allowing toggled tool buttons . . . . . . 6- 46 Adding a cool bar component . . . . . . . . 6- 47 Setting the appearance

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

TỪ KHÓA LIÊN QUAN