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

Sams borland c plus plus builder 6 developers guide 2nd edition dec 2002 ISBN 0672324806 pdf

1,1K 119 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.128
Dung lượng 11,9 MB

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

Nội dung

.289 5 Creating Property and Component Editors 291 Creating Custom Property Editors.. With several years of experience in C++Builder and Delphi and having worked onproject teams using Mi

Trang 1

201 West 103rd Street, Indianapolis, Indiana 46290

Borland C++Builder 6 Developer’s

Guide

Paul Gustavson, and

Jarrod Hollingworth

Trang 2

in a retrieval system, or transmitted by any means, electronic,

mechanical, photocopying, recording, or otherwise, without

written permission from the publisher No patent liability is

assumed with respect to the use of the information contained

herein Although every precaution has been taken in the

prepara-tion of this book, the publisher and author assume no

responsibil-ity for errors or omissions Nor is any liabilresponsibil-ity assumed for damages

resulting from the use of the information contained herein

International Standard Book Number: 0-672-32480-6

Library of Congress Catalog Card Number: 2002109779

Printed in the United States of America

First Printing: December 2002

Trademarks

All terms mentioned in this book that are known to be trademarks

or service marks have been appropriately capitalized Sams

Publishing cannot attest to the accuracy of this information Use of

a term in this book should not be regarded as affecting the validity

of any trademark or service mark

Warning and Disclaimer

Every effort has been made to make this book as complete and as

accurate as possible, but no warranty or fitness is implied The

information provided is on an “as is” basis The authors and the

publisher shall have neither liability nor responsibility to any

person or entity with respect to any loss or damages arising from

the information contained in this book or from the use of the CD

or programs accompanying it

Trang 3

Introduction .1

Part I C++Builder Essentials 5 1 Introduction to C++Builder .7

2 C++Builder Projects and More on the IDE .33

3 Programming in C++Builder .81

4 Creating Custom Components .185

5 Creating Property and Component Editors .291

Part II Database Programming 373 6 Borland Database Component Architecture .375

7 Database Programming .383

8 The Borland Database Engine .397

9 Client Datasets and Client Dataset Enhancements .409

10 Interbase Express Component Overview .417

11 ADO Express Components for C++Builder .435

12 Data Access with dbExpress .453

13 XML Document Programming and XML Mapper .467

Part III Windows Programming 489 14 Win 32 API Functional Areas .491

15 Graphics and Multimedia Techniques .579

16 DLLs .627

17 COM Programming .667

Part IV Distributed Computing 713 18 DCOM: Going Distributed .715

19 SOAP and Web Services with BizSnap .749

20 Distributed Applications with DataSnap .775

21 DataSnap Multitier Connections .811

22 Web Server Programming with WebSnap .835

Trang 4

Part VI Appendixes 929

A C++Builder Example Applications .931

B C++ Mobile Application Development .945

C Information Resources .973

D Enabling TXMLDocument for C++Builder Professional .993

Index .1009

Trang 5

Introduction 1

Who Should Read This Book? .1

How This Book Is Organized .2

The Companion CD-ROM .3

C++Builder System Requirements .3

Conventions Used in This Book .3

Part I C++Builder Essentials 5 1 Introduction to C++Builder 7 C++ Language .8

ANSI Compliance .8

Microsoft Compatibility .10

Recommended Language References .11

Borland Language Extensions and Standard Objects .11

try/finally .14

The VCL, Forms, and Components .14

The Form .15

The Component Palette .15

Events and Event Handlers .15

Testing the Program .18

Creating Your First Real Program .18

Commonly Asked Questions .24

What’s New in C++Builder 6? .25

Compatibility with Previous Releases—Projects .26

Compatibility with Previous Releases—Standard C++ Library .26

Compatibility with Previous Releases—Database Program Changes .27

Compatibility with Previous Releases—DsgnIntf Renamed and Split Up .27

Other New Features .27

Linux, Kylix, CLX, EJB, and C++Builder .28

CLX Overview .28

Cross-Platform Help System Integration .29

Trang 6

The C++ Standard Library .30

Containers .30

Memory Management .32

Summary .32

2 C++Builder Projects and More on the IDE 33 C++Builder IDE Features .33

Main Window and Toolbars .33

Project Manager .34

Arranging Windows in the IDE .34

Object Inspector .36

Property Categories in the Object Inspector .37

The Object Tree View .39

Source Code Editor .39

Forms—Save As Text .43

Understanding C++Builder Projects .44

Files Used in C++Builder Projects .45

Project Manager .48

Different Builds for Different Files .49

Custom Build Tools .50

Drag and Drop within Tree to Reorder Compilation .52

Understanding and Using Packages .53

Considerations When Using Packages .57

Using the C++Builder Interactive Debugger .58

Multithreaded Application Debugging .58

Advanced Breakpoints .60

Advanced Breakpoint Features .63

C++Builder Debugging Views .63

Watches, Evaluating, and Modifying .68

The Debug Inspector .69

Advanced Debugging .70

Locating the Source of Access Violations .71

Attaching to a Running Process .72

Using Just-In-Time Debugging .73

Remote Debugging .73

Debugging DLLs .75

Speeding Up Compile Times .76

Precompiled Headers .76

Other Techniques for Speeding Up Compile Times .78

Trang 7

3 Programming in C++Builder 81

Better Programming Practices in C++Builder .82

Use a String Class Instead of char* .82

Understand References and Use Them Where Appropriate .83

Avoid Using Global Variables .86

Understand and Use const in Your Code .92

Be Familiar with the Principles of Exceptions .95

Use new and delete to Manage Memory .100

Understand and Use C++-Style Casts .105

Know When to Use the Preprocessor .106

Learn About and Use the C++ Standard Library .110

VCL Overview .110

It All Starts at TObject .111

Building on Existing Objects .112

Using the VCL .113

The C++ Extensions .116

VCL and CLX .123

Review of the Component Palette .123

Creating User Interfaces .126

Component Templates and Frames .126

Frames .128

Coping with Different Screen Conditions .137

Coping with Complexity in the Implementation of the User Interface .141

Enhancing Usability by Allowing Customization of the User Interface .147

Working with Drag and Drop .154

The Solution .154

The Code .154

How Does It Work? .157

Wrapping Up Drag and Drop .158

Nonvisual Components and Programming .159

Creating Multithreaded Applications .159

Understanding Multitasking .159

Understanding Multithreading .160

Creating a Thread Using API Calls .160

Understanding the TThread Object .164

Trang 8

Understanding the Main VCL Thread .170

Establishing Priorities .173

Timing Threads .175

Synchronizing Threads .178

Summary .183

4 Creating Custom Components 185 Creating, Compiling, and Installing Packages .185

Packaging Components .186

Compiling and Installing Packages .190

Creating Custom Components .191

Understanding Component Writing .191

Writing Nonvisual Components .195

Writing Visual Components .224

Creating Custom Data-Aware Components .255

Registering Components .266

The Streaming Mechanism .269

Advanced Streaming Requirements .270

Streaming Unpublished Properties .271

Distributing Components .276

Where Distributed Files Should Be Placed .276

Naming Packages and Package Units .279

Naming Components .280

Distributing Only a Design Time-Only Package .281

Distributing Components for Different Versions of C++Builder .283

Creating Component Palette Bitmaps .287

Using Guidelines in the Design of Components for Distribution .288

Taking a Look at Other Distribution Issues .288

Summary .289

5 Creating Property and Component Editors 291 Creating Custom Property Editors .294

The GetAttributes() Method .306

The GetValue() Method .306

The SetValue() Method .308

The Edit() Method .309

The GetValues() Method .313

Trang 9

Considerations When Choosing a Suitable Property Editor .314

Properties and Exceptions .316

Registering Custom Property Editors .317

Obtaining a TTypeInfo* (PTypeInfo) from an Existing Property and Class for a Non-VCL Type .319

Obtaining a TTypeInfo* (PTypeInfo) for a Non-VCL Type by Manual Creation .328

How to Obtain a TTypeInfo* for a Non-VCL Type .330

Rules for Overriding Property Editors .330

Using Images in Property Editors .331

The ListMeasureWidth() Method .336

The ListMeasureHeight() Method .337

The ListDrawValue() Method .338

The PropDrawValue() Method .344

The PropDrawName() Method .345

Creating Custom Component Editors .348

The Edit() Method .354

The EditProperty() Method .358

The GetVerbCount() Method .360

The GetVerb() Method .360

The PrepareItem() Method .361

The ExecuteVerb() Method .368

The Copy() Method .369

Registering Component Editors .371

Summary .372

Part II Database Programming 373 6 Borland Database Component Architecture 375 Borland Database Component Types Overview .375

Component Sets .375

The Borland Database Engine .377

BDE Single-Tier and dbGo .379

BDE/SQL Links, IBExpress, dbExpress, and dbGo (Two-Tier) .379

DataSnap Distributed Databases (Multitier) .379

Summary .381

Trang 10

7 Database Programming 383

What Are Data Modules? .383

Why Use a Data Module? .384

How to Use a Data Module in Applications, DLLs, and Distributed Objects .385

What Goes in a Data Module? .387

How to Add Properties to a Data Module? .387

How to Use the Data Module Designer .388

The Object Tree View and the Data Module Designer .388

The Data Diagram Editor .389

Advanced Concepts in Data Module Usage .391

Form Inheritance with Data Modules .391

Handling Uneven Form Inheritance with Data Modules .392

How to Avoid Dependence on Specific User Interfaces .393

How to Work with Application-Specific and Framework Components in Data Modules .393

Data Modules in Packages .396

Summary .396

8 The Borland Database Engine 397 Introduction to the Borland Database Engine (BDE) .397

Single-Tier .398

BDE/SQL Links (Client/Server) .399

ODBC Using the BDE .399

Component Overview .400

Component Architecture .401

Connection Components .401

TTable—Non-SQL Dataset .402

TQuery—SQL Dataset .403

Summary .407

9 Client Datasets and Client Dataset Enhancements 409 Introduction to Client Dataset Concepts .409

Using Basic Client Datasets in the Client/Server Environment .411

Improving Performance with Client Datasets .412

Using Client Datasets in a Multitier Environment .413

Specialized Types of Client Datasets .414

Summary .415

Trang 11

10 Interbase Express 417

Introduction to IBExpress Components .417

Setting Up a Schema .418

Database Rules .420

Generators, Triggers, and Stored Procedures .421

Generators .421

Triggers .421

Stored Procedures .423

Debugging an InterBase Application .424

Database Creation and Connection .424

Using Transactions .427

Accessing Interbase .427

TIBUpdateSQL .427

TIBTable .428

TIBQuery .429

TIBDataSet .429

TIBSQLandTIBStoredProc .429

TIBEvents .429

Setting Up Bug Tracker .430

update,delete,insert,refresh .430

Fields .432

Cached Updates .432

Transactions and Data-Aware Components .432

Bug Tracker Wrap Up .434

Summary .434

11 ADO Express Components for C++Builder 435 ADO Versus BDE .436

Hedging Your Bets .437

Copying Records and Datasets .437

Component Overview .437

How Do They Fit into the VCL? .438

Database Connections .439

TheTADOConnectionClass .439

TheProvider .439

The Connection String .440

The Home of Transactions .440

Accepting the Defaults .441

Trang 12

Accessing a Dataset with TADOTable .441

Setting the Connection for TADOTable .441

Setting the Table Name for TADOTable .441

OpeningTADOTable .442

Using a Data-Source and Data-Aware Controls with TADOTable .442

Iterating Through the TADOTable .442

Adding or Editing Records Through TADOTable .442

Locating Specific Records in TADOTable .442

Using Filters with TADOTable .442

Accessing a Dataset with TADOQuery .443

Running a Stored Procedure with TADOStoredProc .443

Setting Up TADOStoredProc .443

ExecutingTADOStoredProc .444

Getting Results from TADOStoredProc .444

Executing an Update with TADOCommand .444

Setting Up TADOCommand .444

ExecutingTADOCommand .444

UsingTADOCommandfor Dataset Access .445

UsingTADODatasetfor Dataset Access .445

Managing Transactions .445

Using Component Events .445

TADOConnectionEvents .445

TADOCommandEvents .446

TADOCustomDataSetDescendant Events .446

Creating Generic Database Applications .447

Getting a Connection String from the User .447

Getting Table Names .448

Getting Field Names .448

Getting Stored Procedure Names .448

Performance Optimizations .448

Query or Table .448

Cursor Location .449

Cursor Types .449

Buffering .449

Error Handling Issues .450

Multitier Applications and ADO .450

Summary .451

Trang 13

12 Data Access with dbExpress 453

dbExpress .453

Custom dbExpress .454

dbExpress Components .454

TSQLConnection .455

TSQLDataSet .456

Data-Aware Controls .457

Why Unidirectional .458

TSQLClientDataSet .459

TSQLMonitor .460

Migrating from Borland Database Engine (BDE) .463

Migration Example .465

Summary .466

13 XML Document Programming and XML Mapper 467 XML Document Programming .467

XML Document Properties .468

XML Document Interfaces .469

Reading XML Documents .470

Writing XML Documents .471

XML Data Binding .473

XML Mapping Tool .482

Transforming .485

Transformation Demonstration .486

Summary .488

Part III Windows Programming 489 14 Win32 API Functional Areas 491 Win32 API Background .492

Windows Management .494

Windows Management Example .496

Window Animation Effects .512

Message Identifiers .513

Responding to Windows Messages .514

System Services .515

System Services Example .519

Spawning Applications and Discovering Window Handles .538

Trang 14

Graphical Device Interface .542

Shaping Your Applications .543

Multimedia Services .548

Multimedia File Playback .549

Improved Accuracy with the Multimedia Timer .551

Common Controls and Dialogs .555

Common Controls .555

Common Dialogs .558

Shell Features .562

Using ShellExecute() to Open a Browser .563

Using ShellExecuteEx() to Spawn an Application .564

Backing-Up Directories and Files .565

Sending Files to the Recycle Bin .570

International Features .572

Network Services .572

Getting Network Info .573

Adding System Support .576

Summary .578

15 Graphics and Multimedia Techniques 579 The Graphical Device Interface (GDI) .580

The Windows API and the Device Context .580

UsingTCanvas .581

UsingTPen .586

UsingTBrush .588

UsingTFont .590

UsingTColor .591

An Analog Clock Example .592

Working with Images .593

The Windows Bitmap Object .594

Understanding and Using TBitmap .594

JPEG Images .601

GIF Images .605

PNG Images .606

Working with Multimedia .609

The Media Control Interface (MCI) .609

The Waveform Audio Interface .617

Concluding Remarks on the Waveform Audio Interface .625

Trang 15

16 DLLs 627

Creating a DLL Using C++Builder .628

Using the DLL Wizard .629

Filling in DLL Code .630

Adding a DLL Header File .632

Building a DLL .633

Loading a DLL .634

Linking DLLs Statically .634

Loading DLLs Dynamically .636

Exporting and Using DLL Classes .641

Packages Versus DLLs .647

Steps for Creating a Package .647

Using Forms in a DLL .649

Modal SDI Windows .652

MDI Child Windows .653

Shared Memory Support in a DLL .655

Using Microsoft Visual C++ DLLs with C++Builder .661

Using C++Builder DLLs with Microsoft Visual C++ .662

Summary .664

17 COM Programming 667 COM Fundamentals .667

COM Architectural Elements .668

COM Technologies .669

Creating and Using COM Interfaces .671

IUnknown .671

Interface ID .673

Type Libraries .674

Creating an Interface in C++Builder .676

Implementing an Interface in C++Builder .678

Accessing a COM Object .682

Importing a Type Library .685

Adding Automation .686

Adding Automation to an Existing Application .687

Creating an Automation Controller .691

Adding Event Sinks .695

Writing the COM Server .696

Implementing Event Sinks within a Client .702

Trang 16

Recommended Resources .711

Summary .712

Part IV Distributed Computing 713 18 DCOM: Going Distributed 715 What Is DCOM? .715

Windows OS Family and DCOM .716

TheDCOMCnfgUtility Tool .717

Global Security Settings .717

Per-Server Security Settings .720

Field Testing DCOM .723

Creating the Server Application .723

Creating the Client Application .725

Configuring Launch and Access Permissions .728

Configuring Identity .729

Running the Example .730

Programming Security .730

CoInitializeSecurityFunction Parameters .730

UsingCoInitializeSecurity .732

Understanding DLL Clients and Security .734

Implementing Programmatic Access Control .735

Implementing Interface-Wide Security .737

Using the Blanket .739

Summary .747

19 SOAP and Web Services with BizSnap 749 Building Web Services .749

SOAP Server Application .750

SOAP Server Web Module .751

Web Service Interface .754

Deploying the SOAP Server .755

Consuming Web Services .757

WSDL Importer .758

UsingICmInch .763

Using Other Web Services .765

Google Web APIs .766

Google Search Key .766

Google Search .766

Trang 17

20 Distributed Applications with DataSnap 775

Introduction to DataSnap .775

DataSnap Clients and Servers .777

Creating a Simple DataSnap Server .777

DataSnap Server Registration .781

Creating a DataSnap Client .782

Using the Briefcase Model .785

UsingApplyUpdates .789

Implementing Error Handling .790

Demonstrating Reconcile Errors .793

Creating a DataSnap Master-Detail Server .794

Exporting Master-Detail DataSets .796

Creating a DataSnap Master-Detail Client .797

Using Nested Tables .798

Understanding DataSnap Bandwidth Bottlenecks .800

Stateless DataSnap .803

Stateful Versus Stateless DataSnap Servers .803

Deployment .808

Summary .809

21 DataSnap Multitier Connections 811 Accessing the Server Remotely Using DCOM .811

HTTPWebConnection .812

Object Pooling .814

TCP/IPSocketConnection .816

Registered Servers .818

Object Broker .819

New DataSnap Connections .820

TLocalConnection .820

TConnectionBroker .825

TSOAPConnection .829

C++Builder 6 Enterprise Soap Server .830

C++Builder 6 Enterprise SOAP Client .832

Summary .834

22 Web Server Programming with WebSnap 835 WebAppDebugger .835

Default Web Action Item .836

Trang 18

Debug Web Server Application .838

WebSnap Demo .839

WebSnap Components .839

WebSnap Web Module .840

WebSnap Data Module .841

DataSetAdapter .841

WebSnap Page Module .842

Deployment .843

Tweaking .845

WebSnap Architecture .846

Actions Versus Pages .847

WebSnap Web Modules .847

WebSnap Page Modules .847

WebSnap Data Modules .848

WebSnap Versus WebBroker .848

Server Side Scripting .848

WebSnap Adapters .849

WebSnap Producers .852

WebSnap Login .852

WebSnap Application .853

WebSnap Page Module .854

WebUserList .854

Login Page Module .855

LoginFormAdapter .856

Login Form .856

Incorrect Login .857

EndUserSessionAdapter .858

WebSnap Sessions .858

TSessionsService .859

WebSnap Master-Detail Example .864

Primary Key .864

DataSetAdapter .864

WebSnap Page Module .865

Linking Pages by Name .868

Tweaking and Turning .872

Final Deployment .872

Summary .873

Trang 19

Part V Open Tools API 875

Tools API Fundamentals .877

Open Tools API (OTA) .878

Native Tools API (NTA) .878

Tools API Capabilities .878

Creating a Wizard .880

Selecting a Wizard Interface .881

ReconstructingTNotifierObjectfor C++Builder .881

Defining a Custom Wizard Class .886

Registering a Wizard Class .889

The End Result .890

Creating and Using Services .890

Selecting a Service Interface .891

Accessing a Service .892

Utilizing a Service .893

Creating and Using Notifiers .903

Defining a Custom Debugger Notifier Class .904

Utilizing Our Debugger Notifier .910

Creating and Using Creators .915

Defining a Custom Creator Class .916

Utilizing Our Creator .919

Using Editors .922

Debugging Your IDE Extensions .922

Building and Deploying DLLs .923

Recommended Readings .926

Summary .927

Part VI Appendices 929 A C++Builder Example Applications 931 Overview of C++Builder Example Applications .931

”Apps” Example Applications .934

”DBTask” Example Applications .937

”Doc” Example Applications .940

”WebSnap” Example Applications .941

Summary .944

Trang 20

B C++ Mobile Application Development 945

C++ Mobile Edition Overview .946

Symbian SDK .947

C++ Mobile Edition Plug-In .948

Emulator Versus Simulator .949

Creating a Mobile Application .950

Loading the Hello World Example .952

Building a Mobile Application .952

Testing the Application .953

Mobile Project Composition .954

MMP Files .956

BLD.INF File .957

Source Code Files .958

Deploying a Mobile Application .966

PKG and SIS Files .966

Tools and Methods .967

Symbian OS .967

Future Borland C++ Mobile Products .970

Borland ARM C++ Compiler .970

Mobile CLX Framework .970

Additional Resources .971

Summary .971

C Information Resources 973 Borland-Sponsored Web Sites .973

Borland Home Page .973

Borland Developer Network .974

CodeCentral .976

QualityCentral .977

Useful Developer Web Sites .978

C++Builder Sites .979

C++ Resources .980

Components and Tools .980

Web Services .981

Windows Technologies .982

Newsgroups .985

Books and Magazines .986

C++Builder Books .987

Trang 21

General C++ Books .988

Magazines .989

The Borland Developers Conference (BorCon) .989

Summary .990

D Enabling TXMLDocument for C++Builder Professional 993 TXMLDocument VCL Registration Support .994

TXMLDocument VCL Package Assembly .1005

Using TXMLDocument .1006

Summary .1007

Trang 23

Jarrod Hollingworth

Jarrod has been professionally programming since 1993 He is now running his ownbusiness, Backslash (http://www.backslash.com.au), developing software applicationsfor the Internet and key business sectors and working as a software developmentconsultant He has a solid background in C/C++ programming in the telecommuni-cations industry and assisted in the development of the world’s first live

operator–answered GSM (digital mobile) short-messaging system

Starting in 1985 as a self-taught hobbyist programmer in BASIC and Assembly, hemoved to Pascal and C/C++ through completion of a bachelor of science degree incomputing at Deakin University in Australia His professional roles in software devel-opment have ranged from programmer to software department manager

With several years of experience in C++Builder and Delphi and having worked onproject teams using Microsoft Visual C++, he believes that with few exceptionsC++Builder is the best tool for developing Windows applications

Jarrod lives in Melbourne, Australia, with his wife, Linda His other major interestsinclude traveling and cycling Jarrod can be contacted at jarrod@backslash.com.au

Bob Swart

Bob Swart (also known as “Dr.Bob”—http://www.drbob42.com) is author, trainer,consultant, and webmaster for his own company Bob Swart Training & Consultancy

(eBob42) in Helmond, The Netherlands Bob is a technical author for The Delphi

Magazine, Harcore Delphi, C++Builder Developer’s Journal, Der Entwickler, SDGN

Magazine, UK-BUG Developer’s Magazine, has written for the Web sites of DevX,

TechRepublic/CNET, the IBM and Borland protal, and has spoken at (Borland)

conferences all over the world since 1994 Bob is coauthor of The Revolutionary Guide

to Delphi 2, Delphi 4 Unleashed, C++Builder 4 Unleashed, C++Builder 5 Developer’s Guide, Kylix Developer’s Guide, and Delphi 6 Developer’s Guide.

Bob is married to Yvonne and they have two internet-aware children: Erik MarkPascal (8.5 years) and Natasha Louise Delphine (6 years)

Trang 24

maintains a Web site at http://www.temporaldoorway.comfor his efforts in digital art,writing, music and programming advice (including C++ Builder), and a second Website at http://www.newenglandtrailreview.comto indulge his love of the outdoors.

Paul Gustavson

Paul has over 14 years of computer engineering experience supporting a wide variety

of modeling and simulation, software development, and Web technology efforts.Paul is a co-founder of SimVentions, Inc, a software development company thatdevelops and leverages existing technologies and techniques to create innovativeapplications and solutions He has written and presented numerous publications onsimulation interoperability, is a contributing author of the “C++Builder 5 Developer’sGuide,” and the technical editor for “SAMS Teach Yourself UML (2nd Edition).” Paul

is also the chief architect for PhotoVisor, a multimedia slide show creation tool, andXML SkinGen, a developer’s tool for creating skin-able Delphi and C++Builder apps.Paul lives in Virginia with his wife and two boys

Trang 25

with the nights taken from them to work on it.

Paul Gustavson

I’d like to dedicate this book to those that have shown their cation and commitment to me while I’ve squirreled away on this book To my wife Barbara, my two boys Michael and Ryan, my Mom and Dad, and to the God of all creation whose mercies are

dedi-never ending.

Trang 27

Jarrod Hollingworth

This book has opened my eyes to the fact that the publishing process is very

involved indeed As the acquisitions editor, Carol Ackerman took the book onboardand managed the manuscript submissions and the overall schedule Songlin Qiu wasthe development editor for this book Her eagle eye for quality and content-relatedissues ensured that the book as a whole is more than the sum of its parts It was apleasure working with both Carol and Songlin I’d also like to thank technical editorPaul Qualls for his attention to detail, copy editor Chip Gardner (who, with his supe-rior knowledge of English, improved the grammar in just about every paragraph),project editor Matt Purcell, and all other staff at Sams

Finally I’d like to thank each and every author in this book, but in particular BobSwart and Paul Gustavson, who showed exceptional commitment and enthusiasm.With such a large breadth of experience, each author has donated a piece of hisknowledge to make this book an invaluable resource for C++Builder developers

Paul Gustavson

There are so many people to thank for their efforts in helping make this book ble Let me start off on the home front If it was not for the love and encouragementdemonstrated by my wife, Barbara, this past year through my knee surgery, variouswork efforts, and the book writing, I’d be limping through life As proud as you are

possi-of me for what I’ve done Barb, it is nothing compared to what you’ve done for meand the boys I cherish you! To my two boys Michael and Ryan who give me suchjoy and pleasure Whether it’s playing PlayStation, throwing a baseball, or wrestling

on the floor with the dog, you guys know how to keep me real To my Mom andDad and everyone else in my family (Don, Peggie, Kurt, Kathy, Angi, Jim) who haveprayed for me while I’ve burned the candle at both ends It’s your prayers that have

Trang 28

Neal (and anyone else I missed) You guys are a joy to work with Special thanks to

my co-authors: Dr Bob, Mark, and Jarrod It’s been a real privilege to have workedwith you guys in putting together such a great book Let’s hook up at the nextBorCon To the folks at Borland who have provided me their guidance: MarkEdington, Trevor Strudley, Rebecca Martinez, “JT” Thomas, and John Kaster It’s youguys that have created something that we enjoy writing about Special big thanks tothe crew at SAMs who made all this possible: Carol Ackerman, Songlin Qiu, MattPurcell, Chip Gardner, Paul Qualls Without you guys, where would we be? Finally,I’d like to give my thanks to God who never gives up on me and gives me strength.Despite my busyness and forgetfulness, Lord, thank you for never being too busy orforgetting me!

Trang 29

As the reader of this book, you are our most important critic and commentator We

value your opinion and want to know what we’re doing right, what we could dobetter, what areas you’d like to see us publish in, and any other words of wisdomyou’re willing to pass our way

As an associate publisher for Sams, I welcome your comments You can email orwrite me directly to let me know what you did or didn’t like about this book—aswell as what we can do to make our books better

Please note that I cannot help you with technical problems related to the topic of

this book We do have a User Services group, however, where I will forward specifictechnical questions related to the book

When you write, please be sure to include this book’s title and author as well as yourname, email address, and phone number I will carefully review your comments andshare them with the author and editors who worked on the book

Email: feedback@samspublishing.com

Mail: Michael Stephens

Sams Publishing

201 West 103rd StreetIndianapolis, IN 46290 USAFor more information about this book or another Sams title, visit our Web site atwww.samspublishing.com Type the ISBN (excluding hyphens) or the title of a book

in the Search field to find the page you’re looking for

Trang 31

Welcome to Borland C++Builder 6 Developer’s Guide Our goal for this book was to

put forth the most informative and practical reference on C++Builder to date

Building on the success of C++Builder 5 Developer’s Guide, we have concentrated on

the essential elements and capabilities of C++Builder, including the very latestfeatures provided by C++Builder 6

Topics in this edition include fresh material on XML, SOAP, the Windows API, COM,DLLs, VCL, CLX component development, database development, plus much moreincluding a look at mobile application development We’ve gone to great lengths toprovide practical examples and discussions to common issues, and explore topicsnot previously covered As you read through this book, we encourage you to lever-age the concepts and techniques that are presented Our hope is that you’ll find thematerial to be an invaluable guide in helping you build and deploy cutting-edgeC++Builder applications

Who Should Read This Book?

This book is intended for current and potential users of C++Builder What you hold

in your hand is designed to help expand your current C++Builder skills It is not aC++ primer, nor a tutorial in helping you navigate within the C++Builder environ-ment Rather, it’s a guide to help developers in the following ways:

• Maximize use and knowledge of C++Builder and related technologies

• Examine the latest features provided in C++Builder 6

• Facilitate the development of efficient and robust software such as nents, cross-platform applications, and distributed client/server environments

compo-If you already have experience developing applications with C++Builder, are looking

to upgrade to version 6, or simply want to build on your current knowledge, thisbook will provide an excellent reference Although this book will largely draw theinterest of intermediate and advanced users, the organization is laid out so there is anatural progression through most of the chapters and through the book as a wholeallowing it to be also useful to C++Builder neophytes

Trang 32

How This Book Is Organized

This book is organized into several parts and is arranged to accommodate the widebreadth of topics that are considered essential for mastering C++Builder develop-ment:

• Part I: “C++Builder Essentials”—This part, consisting of Chapters 1–5,

contains everything you need to know to make the best use of C++Builderwhen developing applications It starts with an introduction to C++Builder,and its Integrated Development Environment (IDE) It then covers best prac-tices in programming with C++Builder Finally, it moves on to the advancedtopics of creating custom components, their editors and their property editors

• Part II: “Database Programming”—Chapters 6–13 cover this key topic in

C++Builder programming These chapters include information on the use ofBorland’s database engine (the BDE); the important topic of client datasets,which are used for multitier and client/server programming; and a variety ofspecialized component sets including dbGo (formerly known as ADOExpress)and dbExpress (a new component set newly offered in C++Builder 6, which isspecifically designed as a lightweight replacement for the BDE in client/serverscenarios) This part of the book closes with coverage of XML and theXMLMapper, which can be used to make your applications work with XML

• Part III: “Windows Programming”—A frequent topic of discussion

among C++Builder programmers is the use of the Windows API Part III coversthis in detail within Chapters 14–17 This includes a breakdown of the API’sfunctional areas, techniques for graphics and multimedia programming, how

to program and utilize DLLs, and how to create and use COM objects

• Part IV: “Distributed Computing”—Chapters 18–22 cover the important

topic of distributed computing C++Builder offers many tools to help mers devise systems whose components are distributed across multiple comput-ers and networks These chapters cover standards such as DCOM and SOAP,Borland tools such as DataSnap (formerly known as Midas), WebSnap, and how

program-to create Web Services using XML and Borland’s BizSnap

• Part V: “Open Tools API”—Chapter 23 covers the Tools API, which consists

of Borland’s Open Tools API and the Native Tools API, for extending the bilities of the C++Builder and Delphi IDEs As an example, this chapterprogresses through the development of a practical wizard that can be added tothe environment for supporting performance assessments of applications youdevelop using C++Builder

capa-• Part VI: “Appendixes”—The appendixes offer a variety of extras, including

a look at the Borland examples provided by the C++Builder installation CD,

Trang 33

developing mobile applications using the C++ Mobile Edition, some important

information resources for C++Builder, and how to enable Borland’s

TXMLDocumentcontrol for Professional users

The Companion CD-ROM

A companion CD-ROM has been provided that contains the example code and

C++Builder projects highlighted within this book The code is organized by chapter

and can be accessed from the start-up application provided on the CD-ROM Also

provided on the CD-ROM as an added reference, is the full electronic version of the

C++Builder 5 Developer’s Guide.

C++Builder System Requirements

Several segments of the Borland C++Builder 6 Developer’s Guide are intended for users

of C++Builder 6 Professional and Enterprise; nevertheless, the majority of text and

example code is applicable to previous versions of C++Builder We anticipate the

material provided in the book and on the companion CD-ROM will be applicable to

future versions of C++Builder as well

However, the project files found on the CD-ROM strictly adhere to the C++Builder

version 6 format This format is incompatible with previous versions of C++Builder

Therefore, it will be necessary for users of older versions of C++Builder to create new

projects consisting of the code and forms provided on the companion CD-ROM

NOTE

Despite our best efforts, it is inevitable that there will be the occasional error in the text and

accompanying program code In light of this, a list of errata will be provided on the Sam

Publishing Web site at http://www.samspublishing.com

Conventions Used in This Book

This section describes the important typographic conventions and terminology used

in this book Features in this book include the following:

NOTE

Notes give you comments and asides about the topic at hand, as well as full explanations of

certain topics

Trang 34

Tips identify shortcuts and hints on how to use C++Builder more effectively

CAUTION

These warn you of pitfalls that might be encountered during programming

Also look for the occasional side notes within several chapters of this book which

provide greater insight into specific sub-topics

In addition, you’ll find various typeface conventions throughout this book:

• Code lines, commands, variables, directories, and files appear in text in a monospaced font

• Placeholders in syntax descriptions appear in a monospaced italictypeface.Replace the placeholder with the actual filename, parameter, or other elementthat it represents

• New terms and keywords are typically identified using an italic typeface.

• Functions are indicated by open and close parenthesis after the function name.This helps to differentiate functions from properties, variables, and types

Trang 35

4 Creating Custom Components

5 Creating Property and Component Editors

Trang 37

• Commonly Asked Questions

• What’s New in C++Builder 6

• Linux, Kylix, CLX, EJB, andC++Builder

• The C++ Standard Library

Introduction to

C++Builder

This chapter will introduce you to Borland C++Builder,

one of the leading development environments for creating

Internet, desktop, client/server, and distributed

applica-tions C++Builder combines the ease of a RAD

environ-ment with the power and performance of ANSI C++

The C++Builder Integrated Development Environment

(IDE) is where most of your work is done Have a look at

Figure 1.1 to see the user interface of the C++Builder IDE

C++ remains the most widely used language for developing

applications, which range from sophisticated multitier

business systems to high performance data visualization

and hard, real-time systems C++Builder is an excellent

choice for implementing any application

NOTE

For more information on the features and benefits of

C++Builder, see the Features & Benefits and New C++Builder

Users links on the C++Builder Web site at

http://www.borland.com/bcppbuilder/

Trang 38

FIGURE 1.1 The C++Builder IDE.

be compiled by another

The American National Standards Institute (ANSI) was founded in 1918, and is aprivate, nonprofit organization that coordinates the definition and publication ofvoluntary industry standards in a variety of fields As such, they are the perfect orga-nization to take on the problem of standardizing both the C and C++ languages

Trang 39

The document available at their Web site (http://webstore.ansi.org/ansidocstore/

product.asp?sku=ISO%2FIEC+14882%3A1998) is the result of this effort, which was completed in

1998

In the 21stcentury, “ANSI compliance” is a critical factor sought by developers who

want to have the freedom to develop and compile using several different

develop-ment systems, or who need to target more than one operating system or CPU

instruction set

Borland offers a powerful set of proprietary extensions to C++ so that they can

provide the component-oriented features of the Visual Component Library class

framework But, they also provide what might be the highest level of ANSI

compli-ance in the industry You can force the compiler to only accept ANSI-compliant

programs by clicking a check box in the development environment (pick the menu

entry Project, Options; in the dialog box, click the Advanced Compiler tab; and

under Language compliance, choose ANSI), as shown in Figure 1.2

FIGURE 1.2 Project Options showing the ANSI Compliance option set

To be safe, under Source, make sure to leave Nested comments and MFC

compatibil-ity unchecked

Keep in mind that choosing ANSI compliance means that you cannot develop

Windows programs because there are many features of the Windows operating

system that cannot compile under ANSI compliance You also cannot use Borland’s

Visual Component Library (VCL) You can, however, create programs that use

streams for input and output, which are usually referred to as console programs

Trang 40

Microsoft Compatibility

When a program is compiled without ANSI compatibility (for instance, with theBorland compatibility option selected), it will compile programs using Windowsfeatures This is the basic level of Microsoft compatibility

But, some programs won’t compile

For instance, programs that use the older Microsoft Foundation Classes (MFC) willnot compile without using the MFC compatibility check box on the AdvancedCompiler page

This relaxes numerous rules in the compiler, including

• Not allowing spurious semicolons in a class scope

• Not allowing anonymous structs

• Not using the old-style scoping resolution for loops

• Not allowing methods to be declared with a calling convention, where thedeclaration leaves off the calling convention in the definition

• Not trying the operator new if it cannot resolve a call to the operator new

• Not letting you omit the operator and on member functions

• Not allowing a const class that is passed by value to be treated as a trivialconversion, not as a user conversion

• Not allowing you to use a cast to a member pointer as a selector for overloadresolution when the qualifying type of the member pointer is not derived fromthe class in which the member function is declared

• Not accepting declarations with duplicate storage in a class

• Not accepting and ignoring #pragma comment(linker, “,”)directives

In addition to this, you need to link your program with the nafxcw.libMFC ibility library that comes with C++Builder This occurs automatically as a result ofselecting MFC compatibility when compiling with the C++Builder-developmentenvironment, but requires a special flag if compiling and linking from the commandline (the VF option)

compat-Using MFC with the VCL has proven to be somewhat more difficult, in that specificheader file changes have typically needed to be made to avoid conflicts between thenames used by the MFC and by the VCL These are documented at http://www.temporaldoorway.com/programming/cbuilder/otherlibrary/usingvclandmfc.htmforC++Builder versions through 4

Ngày đăng: 19/04/2019, 16:05

TỪ KHÓA LIÊN QUAN