More Ebooks:

Delphi 5 Developer`s Guide

Debugging Applications

Database Prog. with VB 5 in 21 Days, 2nd Ed

Database Developer`s Guide with Visual C++ 4, Second Edition

Database Developer`s Guide with VB4, 2nd Edition

Curious About The Internet

Creating Web Applets with Java

Creating Shockwave Web Pages

Configuring Windows 2000 Server Security

Configuring ISA Server 2000 Building Firewalls for Windows 2000

find on eBook ToC:

Delphi 6 Developer's Guide (Sams Developer's Guides)

Delphi 6 Developer

Xavier Pacheco, Sams

ISBN:0672321157, Edition: , 2001-12-17

Price: $64.99

Table of Contents

Introduction ~ 1
Who Should Read This Book ~ 2
Conventions Used in This Book ~ 2
Delphi 6 Developer's Guide Web Site ~ 2
Getting Started ~ 3

PART I Development Essentials ~ 5

1 Programming in Delphi ~ 7
The Delphi Product Family ~ 8
Delphi: What and Why ~ 10
The Quality of the Visual Development Environment ~ 11
The Speediness of the Compiler Versus the Efficiency of the Compiled Code ~ 12
The Power of the Programming Language Versus Its Complexity ~ 13
The Flexibility and Scalability of the Database Architecture ~ 14
The Design and Usage Patterns Enforced by the Framework ~ 15
A Little History ~ 15
Delphi 1 ~ 16
Delphi 2 ~ 16
Delphi 3 ~ 17
Delphi 4 ~ 18
Delphi 5 ~ 18
Delphi 6 ~ 19
The Delphi IDE ~ 19
The Main Window ~ 20
The Form Designer ~ 22
The Object Inspector ~ 22
The Code Editor ~ 22
The Code Explorer ~ 23
The Object TreeView ~ 23
A Tour of Your Project's Source ~ 24
Tour of a Small Application ~ 26
What's So Great About Events, Anyway? ~ 28
Contract-Free Programming ~ 28
Turbo Prototyping ~ 29
Extensible Components and Environment ~ 29
The Top 10 IDE Features You Must Know and Love ~ 30
1. Class Completion ~ 30
2. AppBrowser Navigation ~ 30
3. Interface/Implementation Navigation ~ 31
4. Dock It! ~ 31
5. The Object Browser ~ 31
6. GUID, Anyone? ~ 31
7. C++ Syntax Highlighting ~ 32
8. To Do. . . ~ 32
9. Use the Project Manager ~ 32
10. Use Code Insight to Complete Declarations and Parameters ~ 33
Summary ~ 33

2 The Object Pascal Language ~ 35
Comments ~ 36
Extended Procedure and Function Features ~ 37
Parentheses in Calls ~ 37
Overloading ~ 37
Default Value Parameters ~ 38
Variables ~ 39
Constants ~ 41
Operators ~ 43
Assignment Operators ~ 43
Comparison Operators ~ 43
Logical Operators ~ 44
Arithmetic Operators ~ 45
Bitwise Operators ~ 46
Increment and Decrement Procedures ~ 46
Do-and-Assign Operators ~ 47
Object Pascal Types ~ 48
A Comparison of Types ~ 48
Characters ~ 50
A Multitude of Strings ~ 51
Variant Types ~ 63
Currency ~ 75
User-Defined Types ~ 75
Arrays ~ 76
Dynamic Arrays ~ 77
Records ~ 78
Sets ~ 80
Objects ~ 82
Pointers ~ 83
Type Aliases ~ 86
Typecasting and Type Conversion ~ 87
String Resources ~ 88
Testing Conditions ~ 88
The if Statement ~ 88
Using case Statements ~ 89
Loops ~ 90
The for Loop ~ 90
The while Loop ~ 91
repeat ~ until ~ 92
The Break() Procedure ~ 92
The Continue() Procedure ~ 92
Procedures and Functions ~ 93
Passing Parameters ~ 94
Scope ~ 98
Units ~ 99
The uses Clause ~ 100
Circular Unit References ~ 101
Packages ~ 101
Using Delphi Packages ~ 102
Package Syntax ~ 102
Object-Oriented Programming ~ 103
Object-Based Versus Object-Oriented Programming ~ 105
Using Delphi Objects ~ 105
Declaration and Instantiation ~ 105
Destruction ~ 106
Methods ~ 107
Method Types ~ 108
Properties ~ 110
Visibility Specifiers ~ 111
Inside Objects ~ 112
TObject: The Mother of All Objects ~ 113
Interfaces ~ 114
Structured Exception Handling ~ 118
Exception Classes ~ 121
Flow of Execution ~ 123
Reraising an Exception ~ 125
Runtime Type Information ~ 126
Summary ~ 127

3 Adventures in Messaging ~ 129
What Is a Message? ~ 130
Types of Messages ~ 131
How the Windows Message System Works ~ 132
Delphi's Message System ~ 133
Message-Specific Records ~ 134
Handling Messages ~ 135
Message Handling: Not Contract Free ~ 138
Assigning Message Result Values ~ 139
The TApplication Type's OnMessage Event ~ 139
Sending Your Own Messages ~ 140
The Perform() Method ~ 140
The SendMessage() and PostMessage() API Functions ~ 141
Nonstandard Messages ~ 142
Notification Messages ~ 142
Internal VCL Messages ~ 143
User-Defined Messages ~ 144
Anatomy of a Message System: VCL ~ 146
The Relationship Between Messages and Events ~ 154
Summary ~ 154

PART II Advanced Techniques ~ 155

4 Writing Portable Code ~ 157
General Compatibility ~ 158
Which Version? ~ 158
Units, Components, and Packages ~ 160
IDE Issues ~ 160
Delphi-Kylix Compatibility ~ 161
Not in Linux ~ 162
Compiler/Language Features ~ 162
Platform-isms ~ 163
New Delphi 6 Features ~ 163
Variants ~ 163
Enum Values ~ 163
$IF Directive ~ 164
Potential Binary DFM Incompatibility ~ 164
Migrating from Delphi 5 ~ 164
Writable Typed Constants ~ 164
Cardinal Unary Negation ~ 164
Migrating from Delphi 4 ~ 165
RTL Issues ~ 165
VCL Issues ~ 165
Internet Development Issues ~ 165
Database Issues ~ 166
Migrating from Delphi 3 ~ 166
Unsigned 32-bit Integers ~ 166
64-Bit Integers ~ 168
The Real Type ~ 168
Migrating from Delphi 2 ~ 168
Changes to Boolean Types ~ 168
ResourceString ~ 169
RTL Changes ~ 169
TCustomForm ~ 169
GetChildren() ~ 170
Automation Servers ~ 170
Migrating from Delphi 1 ~ 171
Summary ~ 171

5 Multithreaded Techniques ~ 173
Threads Explained ~ 174
Types of Multitasking ~ 174
Using Multiple Threads in Delphi Applications ~ 175
Misuse of Threads ~ 175
The TThread Object ~ 176
TThread Basics ~ 176
Thread Instances ~ 180
Thread Termination ~ 180
Synchronizing with VCL ~ 182
A Demo Application ~ 185
Priorities and Scheduling ~ 187
Suspending and Resuming Threads ~ 190
Timing a Thread ~ 190
Managing Multiple Threads ~ 192
Thread-Local Storage ~ 192
Thread Synchronization ~ 196
A Sample Multithreaded Application ~ 210
The User Interface ~ 211
The Search Thread ~ 219
Adjusting the Priority ~ 224
Multithreading BDE Access ~ 227
Multithreaded Graphics ~ 233
Fibers ~ 238
Summary ~ 244

6 Dynamic Link Libraries ~ 247
What Exactly Is a DLL? ~ 248
Static Linking Versus Dynamic Linking ~ 250
Why Use DLLs? ~ 252
Sharing Code, Resources, and Data with Multiple Applications ~ 252
Hiding Implementation ~ 252
Creating and Using DLLs ~ 253
Counting Your Pennies (A Simple DLL) ~ 253
Displaying Modal Forms from DLLs ~ 256
Displaying Modeless Forms from DLLs ~ 259
Using DLLs in Your Delphi Applications ~ 261
Loading DLLs Explicitly ~ 263
The Dynamically Linked Library Entry/Exit Function ~ 266
Process/Thread Initialization and Termination Routines ~ 266
DLL Entry/Exit Example ~ 267
Exceptions in DLLs ~ 271
Capturing Exceptions in 16-Bit Delphi ~ 271
Exceptions and the Safecall Directive ~ 272
Callback Functions ~ 273
Using the Callback Function ~ 276
Drawing an Owner-Draw List Box ~ 276
Calling Callback Functions from Your DLLs ~ 277
Sharing DLL Data Across Different Processes ~ 279
Creating a DLL with Shared Memory ~ 280
Using a DLL with Shared Memory ~ 284
Exporting Objects from DLLs ~ 287
Summary ~ 293

PART III Database Development ~ 295

7 Delphi Database Architecture ~ 297
Types of Databases ~ 298
Database Architecture ~ 299
Connecting to Database Servers ~ 299
Overview of Database Connectivity ~ 299
Establishing a Database Connection ~ 300
Working with Datasets ~ 300
Opening and Closing Datasets ~ 301
Navigating Datasets ~ 305
Manipulating Datasets ~ 310
Working with Fields ~ 315
Field Values ~ 315
Field Data Types ~ 316
Field Names and Numbers ~ 317
Manipulating Field Data ~ 317
The Fields Editor ~ 318
Working with BLOB Fields ~ 324
Filtering Data ~ 330
Searching Datasets ~ 332
Using Data Modules ~ 336
The Search, Range, Filter Demo ~ 337
Bookmarks ~ 347
Summary ~ 348

8 Database Development with dbExpress ~ 349
Using dbExpress ~ 350
Unidirectional, Read-Only Datasets ~ 350
dbExpress Versus the Borland Database Engine (BDE) ~ 350
dbExpress for Cross-Platform Development ~ 351
dbExpress Components ~ 351
TSQLConnection ~ 351
TSQLDataset ~ 354
Backward Compatibility Components ~ 358
TSQLMonitor ~ 358
Designing Editable dbExpress Applications ~ 359
TSQLClientDataset ~ 359
Deploying dbExpress Applications ~ 360
Summary ~ 361

9 Database Development with dbGo for ADO ~ 363
Introduction to dbGo ~ 364
Overview of Microsoft's Universal Data Access Strategy ~ 364
Overview of OLE DB, ADO, and ODBC ~ 364
Using dbGo for ADO ~ 365
Establishing an OLE DB Provider for ODBC ~ 365
The Access Database ~ 367
dbGo for ADO Components ~ 367
TADOConnection ~ 368
Bypassing/Replacing the Login Prompt ~ 370
TADOCommand ~ 372
TADODataset ~ 373
BDE-Like Dataset Components ~ 373
TADOQuery ~ 375
TADOStoredProc ~ 375
Transaction Processing ~ 375
Summary ~ 377

PART IV Component-Based Development ~ 379

10 Component Architecture: VCL and CLX ~ 381
More on the New CLX ~ 383
What Is a Component? ~ 383
Component Hierarchy ~ 384
Nonvisual Components ~ 385
Visual Components ~ 385
The Component Structure ~ 387
Properties ~ 388
Types of Properties ~ 389
Methods ~ 390
Events ~ 390
Streamability ~ 392
Ownership ~ 393
Parenthood ~ 394
The Visual Component Hierarchy ~ 394
The TPersistent Class ~ 395
TPersistent Methods ~ 395
The TComponent Class ~ 395
The TControl Class ~ 397
The TWinControl and TWidgetControl ~ 398
The TGraphicControl Class ~ 399
The TCustomControl Class ~ 400
Other Classes ~ 400
Runtime Type Information ~ 403
The TypInfo.pas Unit: Definer of Runtime Type Information ~ 405
Obtaining Type Information ~ 407
Obtaining Type Information on Method Pointers ~ 416
Obtaining Type Information for Ordinal Types ~ 420
Summary ~ 428

11 VCL Component Building ~ 429
Component Building Basics ~ 430
Deciding Whether to Write a Component ~ 430
Component Writing Steps ~ 431
Deciding on an Ancestor Class ~ 432
Creating a Component Unit ~ 433
Creating Properties ~ 435
Creating Events ~ 445
Creating Methods ~ 451
Constructors and Destructors ~ 452
Registering Your Component ~ 454
Testing the Component ~ 456
Providing a Component Icon ~ 458
Sample Components ~ 459
Extending Win32 Component Wrapper Capabilities ~ 459
TddgRunButton - Creating Properties ~ 470
TddgButtonEdit - Container Components ~ 477
Design Decisions ~ 477
Surfacing Properties ~ 478
Surfacing Events ~ 478
TddgDigitalClock - Creating Component Events ~ 481
Adding Forms to the Component Palette ~ 485
Summary ~ 488

12 Advanced VCL Component Building ~ 489
Pseudo-Visual Components ~ 490
Extending Hints ~ 490
Creating a THintWindow Descendant ~ 490
An Elliptical Window ~ 493
Enabling the THintWindow Descendant ~ 494
Deploying TDDGHintWindow ~ 494
Animated Components ~ 494
The Marquee Component ~ 494
Writing the Component ~ 495
Drawing on an Offscreen Bitmap ~ 495
Painting the Component ~ 497
Animating the Marquee ~ 498
Testing TddgMarquee ~ 508
Writing Property Editors ~ 510
Creating a Descendant Property Editor Object ~ 511
Editing the Property As Text ~ 513
Registering the New Property Editor ~ 517
Component Editors ~ 522
TComponentEditor ~ 523
TDefaultEditor ~ 524
A Simple Component ~ 524
A Simple Component Editor ~ 525
Registering a Component Editor ~ 526
Streaming Nonpublished Component Data ~ 527
Defining Properties ~ 528
An Example of DefineProperty() ~ 529
TddgWaveFile: An Example of DefineBinaryProperty() ~ 530
Property Categories ~ 538
Category Classes ~ 539
Custom Categories ~ 540
Lists of Components: TCollection and TCollectionItem ~ 543
Defining the TCollectionItem Class: TRunBtnItem ~ 546
Defining the TCollection Class: TRunButtons ~ 546
Implementing the TddgLaunchPad, TRunBtnItem, |and TRunButtons Objects ~ 547
Editing the List of TCollectionItem Components with a Dialog Property Editor ~ 555
Summary ~ 561

13 CLX Component Development ~ 563
What Is CLX? ~ 564
The CLX Architecture ~ 565
Porting Issues ~ 568
No More Messages ~ 569
Sample Components ~ 570
The TddgSpinner Component ~ 570
Design-Time Enhancements ~ 584
Component References and Image Lists ~ 591
Data-Aware CLX Components ~ 598
CLX Design Editors ~ 608
Packages ~ 613
Naming Conventions ~ 613
Runtime Packages ~ 615
Design-Time Packages ~ 618
Registration Units ~ 621
Component Bitmaps ~ 622
Summary ~ 623

14 Packages to the Max ~ 625
Why Use Packages? ~ 626
Code Reduction ~ 626
A Smaller Distribution of Applications - Application Partitioning ~ 626
Component Containment ~ 627
Why Not Use Packages? ~ 627
Types of Packages ~ 628
Package Files ~ 628
Using Runtime Packages ~ 629
Installing Packages into the Delphi IDE ~ 629
Creating Packages ~ 630
The Package Editor ~ 630
Package Design Scenarios ~ 631
Package Versioning ~ 635
Package Compiler Directives ~ 635
More on {$WEAKPACKAGEUNIT} ~ 636
Package Naming Conventions ~ 637
Extensible Applications Using Runtime (Add-In) Packages ~ 637
Generating Add-In Forms ~ 637
Exporting Functions from Packages ~ 644
Launching a Form from a Package Function ~ 644
Obtaining Information About a Package ~ 648
Summary ~ 651

15 COM Development ~ 653
COM Basics ~ 654
COM: The Component Object Model ~ 654
COM Versus ActiveX Versus OLE ~ 655
Terminology ~ 655
What's So Great About ActiveX? ~ 656
OLE 1 Versus OLE 2 ~ 657
Structured Storage ~ 657
Uniform Data Transfer ~ 657
Threading Models ~ 657
COM+ ~ 658
COM Meets Object Pascal ~ 658
Interfaces ~ 658
Using Interfaces ~ 661
The HResult Return Type ~ 666
COM Objects and Class Factories ~ 667
TComObject and TComObjectFactory ~ 667
In-Process COM Servers ~ 669
Out-of-Process COM Servers ~ 672
Aggregation ~ 672
Distributed COM ~ 673
Automation ~ 673
IDispatch ~ 674
Type Information ~ 675
Late Versus Early Binding ~ 676
Registration ~ 676
Creating Automation Servers ~ 676
Creating Automation Controllers ~ 692
Advanced Automation Techniques ~ 700
Automation Events ~ 700
Automation Collections ~ 713
New Interface Types in the Type Library ~ 723
Exchanging Binary Data ~ 724
Behind the Scenes: Language Support for COM ~ 727
TOleContainer ~ 733
A Small Sample Application ~ 733
A Bigger Sample Application ~ 735
Summary ~ 746

16 Windows Shell Programming ~ 747
A Tray-Notification Icon Component ~ 748
The API ~ 748
Handling Messages ~ 751
Icons and Hints ~ 752
Mouse Clicks ~ 752
Hiding the Application ~ 755
Sample Tray Application ~ 762
Application Desktop Toolbars ~ 764
The API ~ 764
TAppBar: The AppBar Form ~ 766
Using TAppBar ~ 775
Shell Links ~ 779
Obtaining an IShellLink Instance ~ 781
Using IShellLink ~ 781
A Sample Application ~ 790
Shell Extensions ~ 799
The COM Object Wizard ~ 801
Copy Hook Handlers ~ 801
Context Menu Handlers ~ 808
Icon Handlers ~ 818
InfoTip Handlers ~ 827
Summary ~ 833

17 Using the Open Tools API ~ 835
Open Tools Interfaces ~ 836
Using the Open Tools API ~ 839
A Dumb Wizard ~ 839
The Wizard Wizard ~ 843
DDG Search ~ 855
Form Wizards ~ 868
Summary ~ 876

PART V Enterprise Development ~ 877

18 Transactional Development with COM+/MTS ~ 879
What Is COM+? ~ 880
Why COM? ~ 880
Services ~ 881
Transactions ~ 881
Security ~ 882
Just-In-Time Activation ~ 888
Queued Components ~ 888
Object Pooling ~ 897
Events ~ 898
Runtime ~ 906
Registration Database (RegDB) ~ 907
Configured Components ~ 907
Contexts ~ 907
Neutral Threading ~ 907
Creating COM+ Applications ~ 908
The Goal: Scale ~ 908
Execution Context ~ 908
Stateful Versus Stateless ~ 909
Lifetime Management ~ 910
COM+ Application Organization ~ 910
Thinking About Transactions ~ 911
Resources ~ 912
COM+ in Delphi ~ 912
COM+ Wizards ~ 912
COM+ Framework ~ 913
Tic-Tac-Toe: A Sample Application ~ 916
Debugging COM+ Applications ~ 934
Summary ~ 935

19 CORBA Development ~ 937
CORBA Features ~ 938
CORBA Architecture ~ 939
OSAgent ~ 941
Interfaces ~ 942
Interface Definition Language (IDL) ~ 942
Basic Types ~ 943
User-Defined Types ~ 944
Aliases ~ 944
Enumerations ~ 944
Structures ~ 944
Arrays ~ 944
Sequences ~ 944
Method Arguments ~ 945
Modules ~ 945
The Bank Example ~ 946
Complex Data Types ~ 958
Delphi, CORBA, and Enterprise Java Beans (EJBs) ~ 965
A Crash Course in EJBs for Delphi Programmers ~ 965
An EJB Is a Specialized Component ~ 966
EJBs Live Within a Container ~ 966
EJBs Have Predefined APIs ~ 966
The Home and Remote Interfaces ~ 966
Types of EJBs ~ 967
Configuring JBuilder 5 for EJB Development ~ 967
Building a Simple ôHello, worldö EJB ~ 968
CORBA and Web Services ~ 975
Creating the Web Service ~ 975
Creating the SOAP Client Application ~ 977
Adding the CORBA Client Code to the Web Service ~ 978
Summary ~ 981

20 BizSnap Development: Writing SOAP-Based Web Services ~ 983
What Are Web Services? ~ 984
What Is SOAP? ~ 984
Writing a Web Service ~ 985
A Look at the TWebModule ~ 985
Defining an Invokable Interface ~ 986
Implementing an Invokable Interface ~ 987
Testing the Web Service ~ 989
Invoking a Web Service from a Client ~ 991
Generating an Import Unit for the Remote Invokable Object ~ 993
Using the THTTPRIO Component ~ 994
Summary ~ 995

21 DataSnap Development ~ 997
Mechanics of Creating a Multitier Application ~ 998
Benefits of the Multitier Architecture ~ 999
Centralized Business Logic ~ 999
Thin-Client Architecture ~ 1000
Automatic Error Reconciliation ~ 1000
Briefcase Model ~ 1000
Fault Tolerance ~ 1000
Load Balancing ~ 1000
Typical DataSnap Architecture ~ 1001
Server ~ 1001
Client ~ 1004
Using DataSnap to Create an Application ~ 1007
Setting Up the Server ~ 1007
Creating the Client ~ 1009
More Options to Make Your Application Robust ~ 1015
Client Optimization Techniques ~ 1015
Application Server Techniques ~ 1018
Real-World Examples ~ 1027
Joins ~ 1027
More Client Dataset Features ~ 1039
Two-Tier Applications ~ 1039
Classic Mistakes ~ 1041
Deploying DataSnap Applications ~ 1041
Licensing Issues ~ 1042
DCOM Configuration ~ 1042
Files to Deploy ~ 1043
Internet Deployment Considerations (Firewalls) ~ 1044
Summary ~ 1046

PART VI Internet Development ~ 1047

22 ASP Development ~ 1049
Understanding Active Server Objects ~ 1050
Active Server Pages ~ 1050
The Active Server Object Wizard ~ 1052
Type Library Editor ~ 1055
ASP Response Object ~ 1059
First Run ~ 1060
ASP Request Object ~ 1061
Recompiling Active Server Objects ~ 1062
Running Active Server Pages Again ~ 1063
ASP Session, Server, and Application Objects ~ 1065
Active Server Objects and Databases ~ 1066
Active Server Objects and NetCLX Support ~ 1069
Debugging Active Server Objects ~ 1071
Debugging Active Server Objects with MTS ~ 1071
Debugging Using Windows NT 4 ~ 1073
Debugging Using Windows 2000 ~ 1074
Summary ~ 1076

23 Building WebSnap Applications ~ 1077
WebSnap Features ~ 1078
Multiple Webmodules ~ 1078
Server-side Scripting ~ 1078
TAdapter Components ~ 1078
Multiple Dispatching Methods ~ 1079
Page Producer Components ~ 1079
Session Management ~ 1079
Login Services ~ 1079
User Tracking ~ 1080
HTML Management ~ 1080
File Uploading Services ~ 1080
Building a WebSnap Application ~ 1080
Designing the Application ~ 1080
Adding Functionality to the Application ~ 1089
Navigation Menu Bar ~ 1089
Logging In ~ 1092
Managing User Preference Data ~ 1095
Persisting Preference Data Between Sessions ~ 1099
Image Handling ~ 1101
Displaying Data ~ 1103
Converting the Application to an ISAPI DLL ~ 1107
Advanced Topics ~ 1107
LocateFileServices ~ 1108
File Uploading ~ 1109
Including Custom Templates ~ 1111
Custom Components in TAdapterPageProducer ~ 1112
Summary ~ 1114

24 Wireless Development ~ 1115
Evolution of Development - How Did We Get Here? ~ 1116
Pre-1980s: Here There Be Dragons ~ 1116
Late 1980s: Desktop Database Applications ~ 1117
Early 1990s: Client/Server ~ 1117
Late 1990s: Multitier and Internet-Based Transactions ~ 1117
Early 2000s: Application Infrastructure Extends to Wireless Mobile Devices ~ 1117
Mobile Wireless Devices ~ 1118
Mobile Phones ~ 1118
PalmOS Devices ~ 1118
Pocket PC ~ 1119
RIM BlackBerry ~ 1119
Radio Technologies ~ 1119
GSM, CDMA, and TDMA ~ 1119
CDPD ~ 1119
3G ~ 1120
GPRS ~ 1120
Bluetooth ~ 1120
802.11 ~ 1120
Server-Based Wireless Data Technologies ~ 1121
SMS ~ 1121
WAP ~ 1121
I-mode ~ 1132
PQA ~ 1132
Wireless User Experience ~ 1136
Circuit-Switched Versus Packet-Switched Networks ~ 1137
Wireless Is Not the Web ~ 1137
The Importance of Form Factor ~ 1137
Data Entry and Navigation Techniques ~ 1137
M-Commerce ~ 1138
Summary ~ 1138