PowerBuilder 5: A Developers Guide [Paperback ed.] 1558514732, 9781558514737

PowerBuilder is a powerful object-oriented client/server front- end development system for Microsoft Windows. Intended f

600 33 74MB

English Pages 898 [932] Year 1995

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

PowerBuilder 5: A Developers Guide [Paperback ed.]
 1558514732, 9781558514737

Citation preview

PowerBuilder 5 A Developer's Guide

"'ikv

r^rr

David McClanahan

m&t

• The most complete, easy-to-follow guide • Based on David McClanahan's proven

to

PowerBuilder available

series of PowerBuilder

seminars

[i

• Complete coverage of PowerBuilder Desktop, PowerScript, and the PowerBuilder Painters

• Comprehensive guidelines

for creating client/server applications

PowerBuilder

5:

A Developer's Guide David

McClanahan

M&ri

EH

M&T 1 M&T Books

™ C^P S

""

A A

Division of MIS:Press, Inc.

Subsidiary of Henry Holt and

Company,

Inc.

115 West 18th Street

New York, New York

10011

http://www.mispress.com Copyright

©

1996, by David McClanahan.

Printed in the United States of America All rights reserved.

No

part of this

book may be reproduced or transmitted

in

any form or

by any means, electronic or mechanical, including photocopying, recording, or by any

mation storage and

retrieval system,

infor-

without prior written permission from the Publisher.

Contact the Publisher for information on foreign

rights.

Limits of Liability and Disclaimer of Warranty

The Author and Publisher

of this

and the programs contained

in

of the theories

and programs

it.

to

book have used

These

efforts

shall

any event

liable in

or arising out

of,

All products,

names and

tive

of

any kind, expressed or implied, with regard

programs or the documentation contained

not be

book

determine their effectiveness.

The Author and Publisher make no warranty to these

their best efforts in preparing the

include the development, research, and testing

for incidental or

in this book.

The Author and Publisher

consequential damages in connection with,

the furnishing, performance, or use of these programs. services are trademarks or registered trademarks of their respec-

companies.

Library of Congress Cataloging-in-Publication Data

ISBN 1-55851-441-4

1098765432

1

Associate Publisher: Paul Farrell

Executive Editor: Cary Sullivan

Production Editor: Anthony Washington

Editor: Michael Sprague

Copy

Copy

Edit

Manager: Shari Chappell

Editor: Karen Tongish

Dedication

To

Saint KirpalSingh, founder of the

World Fellowship

of Religions,

and to Rajinder Singh

who

continues his work through the

Science of Spirituality Center

www.sos.org

Best

Dave McClanahan

CONTENTS

CHAPTER

I

:

Introduction to PowerBuilder 5

The Development Environment The PowerBuilder Painters Displaying Text Labels

in

1

2

the Toolbars

Displaying PowerTips

2

5

Displaying MicroHelp

5

Customizing the Presentation Style Get to Know These Features Online Help Find Option Creating Bookmarks Using the Help Button Help Option Microhelp and PowerTips

The Context-Sensitive Popup Menu The PowerScript Language Pasting Code Examples into Your The Text File Editor The Object Browser Data Windows

1

6

7 8 8

10

10 11 11

12

12

Scripts

Object-Oriented Features Properties, Events, and Functions

13 13

14 15 15

16

Properties

17

Events

17

Functions

17

The PowerBuilder

Painters

PowerBuilder Painters Overview

CHAPTER

2:

The PowerScript Language

The PowerScript Language Identifiers

PowerScript Text Line Continuation

18

19

23 24 24 25 26

Contents

Comments Dot Notation Data Types Using Special ASCII Characters

26 27 28 33

The NULL Value The Any Datatype

34

Classes

34

33

36

Declaring Variables Datatype Conversions

37 38

Arrays

Global Scope

40 40

Local Scope

41

Instance Variables

41

Variable Access Levels

42

The Shared Scope

44 45 46 46 48 48

Variable Scope Options

Labeling Scope

in Identifiers

Resolving Duplicate Variable Passing Variables

in

Names

Function Calls

Declaring Constants

PowerScript Language Statements

The

IF Statement Operator Precedence

The

CHOOSE CASE Statement

LOOPING

Constructs

The FOR... NEXT Loop The CONTINUE and EXIT Statements The GOTO Statement The HALT Statement The RETURN Statement The CREATE and DESTROY Statements The CALL Statement The Pronoun Reserved Words

48

49 51

51

52 53

54 54 55 55

55 56

This

56

Parent

57

ParentWindow

58 59

Super PowerScript Structures Global Structures Object-Level Structures

Window-Level Structures PowerBuilder Functions

User-Denned Functions

The Object Browser

59 59 61

63 64

65 70

Contents

The PowerScript Debugger

70

Adding a Breakpoint Running the Debugger Displaying and Modifying Variables Using the Debugger PowerBuilder Naming Conventions

CHAPTER:

3

The PowerScript Painter

The PowerScript The Drop-Down

Boxes

Paste Global List Box Paste Instance List Box Paste Shared List Box Paste

Edit

Argument List Box Object/Window List Box

Menu

Paste Options

Paste Function

77

79 79 79 80 80 80 80 81

SQL

81

Paste Statement

82

Paste

Entering and Editing Text

83

Selecting Text

To Cut, Copy,

83 Clear, or Replace Selected Text

Keyboard Shortcuts

Cut and Paste Functions The PowerScript Painter Menu Options for the

Menu Menu Search Menu Declare Menu Design Menu File

Edit

Import and Export Exporting Text

Compiling PowerScript Code Customizing the Editor Context-Sensitive Help The Object Browser Selecting Another Object Editing Function Declarations

CHAPTER:

4 Creating

PowerBuilder Application Application Painter

The

84 84

Pasting Text

A

74 75 76

78

Select Event List Box

Paste

73

77

Painter List

71

PowerBuilder Applications

85 86

86 86 87 87 88 88 89 89 90 91

92 96 97

99 99 100

Contents

Opening Application

101

Painter

Application Programs and Application Objects

102

PowerBuilder Application Libraries The Application Executable

102

Batch Applications

103

Opening an Application Opening an Existing Application Creating

a

New

02

103 103

105

Application

Setting Application Properties

Selecting the Application Icon Setting Default Fonts

107 107 08 109 110 1

Specifying the Library Search

List

The Search Order The Project Painter

Ill

Closing the Application Painter Properties, Events,

1

and Functions

114 114

Application Object Properties

115

Dot Notation Addressing

115

Application Object Events

Using the PowerScript

Editor,

116

Coding an Event

The Application-Level Events The Application Open Event The Application Close Event The Application Idle Event The Application SystemError Event Application Object Functions

The Application Painter Menus The Application Painter Menu Options Building An Application Creating

a

New

Application

116

117

117 118

118 118

119 1

20

121

122 1

22

Create the Application and Library

123

Add Code

123

Run

to the

Open Event

the Application

124

Create an Executable

125

Run the Executable from Windows

1

Library Painter

The

26

126

Application Initialization File

Developing the Exercise Applications Example: FirstApp

128

30 130 1

Running FirstApp

131

FirstApp

133

— Step-by-Step

Add Code What's Next

to the

Open Event

134 .137

Contents

CHAPTER:

5 Creating Windows Window Painter The Window Painter Dialog Box The 3D Look Window Painter Toolbars

The

139

141

Style Toolbar

Setting Color Options

Defining

The The The The The The

a

Window's Style

Sheet

147 1

1

and Menus

1

1

151

New Window

153

Other Window Options

1

Window The Window Painter Popup Menu Window Scripts Window Events Window Functions Window Attributes Window Variables Window Painter Menus The Window Painter Menu Options Saving the

56

156

156 1

56

1

57 59 60

1

62

1

1

163 163

167

Example: FirstWin Running FirstWin FirstWin Step-by-Step

168



6 Manipulating

49 49 50 50

150

Other Window Attributes

1

Window

Controls

Adding Controls to a Window Working with Controls Adding a Control to a Window Aligning Controls with the Alignment Function Adjusting the Spacing of Controls

Automatically Sizing Controls

The Control Properties Dialog Box Naming a Control Setting Text In a Control

47

148

1

for Sheets

44 47

1

Frame with Microhelp

CHAPTER:

42

1

Window Types

Resizing the

42

1

144

Menus

Recommendation

MDI MDI

1

143

Window Type Main Window Child Window Popup Window Response Window MDI Frame Window

Sheets and

39

1

141

69

77

1

1

79

181 181 1

1

85 87

87 89 89 190 1

1

1

Contents

Setting Control Attributes

191

Accelerators for Controls

191

Change an

193

Attribute

Control

194

PowerBuilder Units (PBUs) Colors in PowerBuilder Applications

194

Duplicating

a

195

Color Values

195

The 3D Look Show Invisibles

196

CHAPTER:

7

1

Window

Controls

96

197

Description, Properties, Events, and Functions

198

The Window Controls The Window Controls Example

198

Controls by Category

Control Popup

Menu Options

CommandButtons Adding a CommandButton to a Window CommandButton Properties Dialog Box CommandButton Properties CommandButton Events CommandButton Functions

199

99 200 1

201 201

PictureButton Properties

202 204 206 207 207 209

PictureButton Events

211

PictureButton Functions

212 213 214 216 217 219

PictureButtons

SingleLineEdit Controls SingleLineEdit Control Properties SingleLineEdit Control Events

SingleLineEdit Control Functions

EditMask Control Defining Spin Controls

EditMask Control Properties EditMask Control Events EditMask Control Functions MultiLmeEdit Control

221

MultiLineEdit Control Properties

223 225 226 228 229

MultiLineEdit Control Events

231

MultiLineEdit Control Functions RichTextEdit Control

232 234 235 237 239 242

RichTextEdit Control Properties RichTextEdit Control Events RichTextEdit Control Functions List

Box Controls

Contents

244 246 247 248

ListBox Control Properties ListBox Control Events ListBox Control Functions

DropDownPictureListBox Controls DropDownPictureListBox Control DropDownPictureListBox Control DropDownPictureListBox Control DropDownPictureListBox Controls DropDownPictureListBox Control DropDownPictureListBox Control DropDownPictureListBox Control

Properties

251

Events

Events

252 253 255 258 260

Functions

261

Functions Properties

263 265 266

Picture Controls Picture Control Properties Picture Control Events Picture Control Functions

StaticText Controls StaticText Properties Dialog

Window

StaticText Properties

267 268 269 269

StaticText Events

271

StaticText Functions

272 272 273 273 276 278 279 280 28 283 285 286 287 289 290 290

ListView Controls ListView Properties Dialog

Window

ListView Properties ListView Events ListView Functions

TreeView Controls TreeView Properties Dialog TreeView Properties TreeView Events TreeView Functions RadioButton Controls RadioButton Properties RadioButton Events RadioButton Functions

GroupBox Controls CroupBox Properties GroupBox Functions CheckBox Controls CheckBox Properties CheckBox Events CheckBox Functions HScrollBar HScrollBar Properties HScrollBar Events

Window

291

293 2

l

M

295 296 ~

(

>~

298 299 300

1

Contents

301

HScrollBar Functions VScrollBar Properties

302 303

VScrollBar Events VScrollBar Functions

304 305

VScrollBar

306 307 308 308

Line Controls

Line Properties Line Functions

Oval Controls Oval Properties Oval Functions

309 310 310

Rectangle Controls Rectangle Properties

311

Rectangle Functions

312 312 313 314 314 317 319 320

RoundRectangle Controls RoundRectangle Properties RoundRectangle Functions Tab Controls Tab Control Properties Tab Control Events Tab Control Functions Drag and Drop Drag-and-Drop Functions CONTROLl Example Program

321

Create the w_second

324 325 327 327 328 329 330

Return to the

331

CONTROLl— Step-by-Step Create the Application and Library Create the Main

Add Code

Window

Open Window w_first Window w_second Window

to the Application

Return to the

Event

Run the Application

CHAPTER:

8 PowerBuilder Events, Functions,

and User Events Event-Driven Programming Messages Events A PowerBuilder Application Events Experiment with Eventsl 1

335 339

:

1

The Order of Constructor Events PowerBuilder Events User-Defined Functions

34 341

342 343 343 345 346 348 349

Contents

Object-Level Functions

351

Function Return Value Type

352

Function Argument List

353 353

Standard User-Objects and User-Defined Functions

Object Function Access Level Sample Function Defining User Events Creating a User Event Creating a Custom Event Creating a Parameterized Custom Event Mapping a Windows' Event The Other Event The Message Object Initiating Functions and Events Events2 Example Program Events2 Step-by-Step Create the Application and Library

A



Create the Main Window Add a Function to w_main Add Code to the Application Open Event Add a User Event to the w_main Window Add Code to the w_main Open Event Add Code to the ue_init Event Add Controls to the Window Add a User Event to lb Add Code to the ue_add_item Event Add Code to the sle_l Modified Event Add Another User Event to lb Add Code to the lb we_mousemove Event Add Code to the sle_l DragDrop Event Summary 1

1

1

CHAPTER:

Embedded SQL

9

DataWindow

Objects:

A

Preview

SQL Statements Embedded SQL Statements Creating SQL Statements Paste SQL Cursor SQL Statements

354 354 355 355 357 358 361

362 363 365 366

367 367 367 369 370 370 371

372 372 373 374 374 375 375 376 376

377 377 377 379 379 380 38

1

Declare Cursor

381

Fetch Cursor

382 383 384 384

Update Cursor Delete Cursor

Non-Cursor

SQL Statements

1

Contents

Query

388 388

Painter

Transaction Objects

The SQLCode The Application Initialization Example:

390 391

File

SQLApp

Running SQLApp Using SQLApp

SQLApp— Step-by-Step Create the Application and Library

393 393 395 397 397 397 399

Create the Main

Window

Add Code Add Code Add Code

Window

400

w_embedded_sql Window Save the Window and Run the Application

401

to the Application to the

Open

to the

Selecting and Updating Blobs

UPDATEBLOB SQL

CHAPTER:

Menus

1

Introduction to the

Creating

Statement

Menu

Painter

Menus

Item Events

Menus Menus

Creating Cascading Creating Popup

Menu

Item Properties

General Attributes Style Attributes

Shortcut Keys and Accelerators

Toolbar Tab Pictures

MDI

Tab

Applications

Adding

MDI

Microhelp

The MDI Toolbar Adding

Scripts

Previewing the Menu Saving the Menu Attaching the Menu to Menu Item Attributes Menu Item Functions

a

408 408 409

411

Adding Menu Bar Items Adding Menu Items

Menu

Event

Window

MENUS Example MENUS — Step-by-Step

The

Create the Application and Library

411

412 414 414 415 416 417 418 418 419 420 422 423 424 424 425 426 427 427 427 428 429 430 43 43

1

Contents

Create

Menu m_main Window

Create the Main

Add Code to the Application Open Event Add a Function to m_main Add Another Function to m_main Copy Windows to ZMENUS.PBL Add Code to m_main Menu Item Events The w_environment Window

CHAPTER:

I

I

Introduction to

DataWindows

DataWindow Concepts DataWindow Objects and Controls DataWindow Objects DataWindow Controls Creating a New DataWindow Object DataWindow Creation The Data Source and Presentation Style Data Sources Presentation Style

DataWindow Data Sources Quick Select The Quick Select Dialog Window The SQL Select Data Source Option The Query Data Source Option The External Data Source Option The Stored Procedure Data Source Option Presentation Styles dwstyles.pbl

CHAPTER:

1

2

The DataWindow Painter

Enhancing DataWindow Objects Customizing the DataWindow Presentation Bands The Header Band The Detail Band The Summary Band The Footer Band Group Bands Croup Header Band Croup Trailer Band Changing the Design Saving the DataWindow Object Modifying the DataWindow .

432 435 439 440 441

442 443 444

447 447 449 450 451

452 453 454 455 456

457 457 458 462 473 474 475 476 476

477 477 478 479 480 480 48 48 482 482 I

482 483 483 483

Contents

Adding DataWindow Objects Selecting

DataWindow Objects

Selecting Multiple Controls

Using the Design Grid Using the Zoom Option Using the Preview Option Aligning Objects with the Alignment Function Adjusting the Spacing of Objects Automatically Sizing of Objects The Style Toolbar Colors Setting the Tab Order

484 484 484 486 488 489 489 491

491

Predefined Calculated Fields

492 494 494 495 497 499 500

Adding Database Columns

501

DataWindow

Properties

Adding Computed Fields DBMS Computations versus DataWindow Computations

The Rows Menu Column Specifications Data Prompt

for Criteria

Retrieve Filtering

and Sorting

Suppressing Repeating Values

Update Properties Creating Groups

Column Attributes The Column Popup Menu The Display as Picture Option Using Column Validation Column Edit Styles The Default Edit Style EditMask Style RadioButton

DropDow nlistBox Style DropDownDataWindow Presentation Styles

Style

502 502 503 503 504 505 507 509 512 514 514 515 518 519 520 522 524 525 527 530

Crosstab

531

Freeform

535 537

Graph Grid

Croup Label

N-Up

539 540 543 '..'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.545

Tabular

Creating Nested Reports

The Composite Report

Presentation Style

Nesting Reports to Create Master-Detail Relationships Data Window Examples

CHAPTER:

13

DataWindow Controls: Adding DataWindows to Your Applications

Overview: Using DataWindow Controls DataWindows with a DBMS Source DataWindows with an External Source Adding a DataWindow Control to a Window DataWindow Control Popup Menu Options Select a DataWindow Object Set the

DataWindow

Attributes

Using DataWindow Controls With Connecting to the Database Disconnecting to the Database Transaction Objects SetTransObject

a

Database

SetTrans

Database Error Handling in DataWindows Updating Data in a DataWindow The DataWindows Edit Control Updating a Row in a DataWindow

DataWindow

Items

Column Number Column Name References by Column Number

Item Reference by Item Reference by

Ranges of Item Status

Codes

DataWindow Programming RetrieveO

InsertRowQ

DeleteRowQ Update!)

COMMIT ROLLBACK DataWindows DataWindow

Sharing Data between

Adding SaveAs

QBE

to a

Print

Dynamically Assigning DataWindow Objects 1

iltcr

Functions

546 547 547 548 550

55 551

552 553 553 554 555

557 559 560 560 560 561

56 563 564

565 567 569 569 570 571 573 574 575 576 576 577 577 577 578 578 580 580 581

58

1

Contents

Sort Functions

The Find Function Data Window Events Retrieving Data into

a DataWindow DataWindow

Printing a

The Object Browser DataWindow Control Attributes DataWindow Control Events DataWindow Control Functions Advanced Functions for a DataWindow Control Graph Functions for a DataWindow Control DataStores

DataStore Attributes DataStore Events DataStore Functions Reports

The DataWindow Example Programs Example Requirements

DBJNITPBL w_main wf_db_init

wf_status_message Global Functions

CHAPTER:

1

4 Multiple

Document

Interface

The MDIAPP Example The OpenSheet Function

MDI

Events

Creating an

MDI Application MDI Frame

Creating the Creating the

Window Parms Structure Window (w_mdi_sheet)

Creating the Sheet

w_mdi_frame Instance Variable w_mdi_frame Window-Level Functions

Add Code

to the Application Open Event Creating the Menus Creating the m_mdi_sheet Menu Creating an MDI Template

CHAPTER:

1

5

User Objects

User Objects Types of User Objects Class Category

582 583 584 584 587 587

587 589 591

596 598 598 599 599 600 604 605 606 607 607 608 609 610

613 613 616 618 618 618 619

620 623 623 626 626 630 632

635 635 636 636

Contents

Assigning the idw_x Data Window Value

637 637 638 639 640 643 643 644 644 646 647 648 650

Using

651

Category Using Visual User Objects The Standard User Object The Example uodemo Program An Example Standard Visual User Object Visual

Create Object-Level Function fu_disable Create Object-Level Function fu_enable Create Object-Level Function fu_get_state

Adding

a

User Object to

a

Window

w_main_with_uos CloseQuery Event

Edit the

Custom Visual User Objects The U_DW_NAV User Object a

Registration Function (or Event)

The U_DW_NAV_VERTICAL User Object The U_DW_NAV_WITH_CLOSE User Object The U_LB_WITH_SEARCH User Object Custom Class User Objects Cross-Window References Standard Class-User Objects External User Objects Advanced Techniques Dynamic User Objects

UO_WITH_STRUCTURES Distributed PowerBuilder

Create the Server Application

DSERVER

653 654 656 660 664 666 668 670 670 676

677 678

Define the Transport Object

678 679 680 680 68

DCLIENT

681

Connection Object Define the Connection Object Communications to MQUE DLL

683 683 684

Create the Server Object Create the Proxy Object Create the Proxy Library

Declare

a

CHAPTER:

1

6

Inheritance

Object-Oriented Concepts Data Abstraction and Encapsulation Classes

Objects u_person Inheritance

u_cmployee

685 685 686 686 687 688 690 690

11

Contents

Why

691

Inherit?

693 693 693 696

Polymorphism Object-Oriented PowerBuilder PowerBuilder Classes

Window

Inheritance

The Snap-to-Grid Option and

697 697 698 699

Inheritance

Inherit.PBL

w_ancestor

w_main w_main2

703

User Object Inheritance

707 707 710

MDI

713

Updating the Ancestor

Menu

Inheritance

Inheritance

CHAPTER:

and Distributing PowerBuilder Applications

17 Developing

715

Distributing Your PowerBuilder Applications

715 716 716 717 717 717 720

Dynamic Libraries PBR Files DISTRIB.PBL Creating

a

PBD

Creating

a

Project

Building the Executable

Using Projects

Managing

72 722 722 723 727 729 730

Libraries

Distributing Applications

Online Help Creating Your Help Text

RoboHELP: The Adding Help

Better

Method

to a PowerBuilder Application

Essential PowerBuilder Tools

73

PowerSoft Infobase CD-ROM CompuServe's PowerSoft Forum Blue Sky Software's RoboHELP Logic Work's ERwin/ERX for PowerBuilder LBMS' Systems Engineer PowerBuilder Applications Developer Magazine Corsoft's

CorDoc

for

73

732 732 732 733 733 733 733 733

PowerBuilder

Frameworks and Class

Libraries

The PowerBuilder Foundation Getting Started with PFC

Class Library .

.735

Contents

CHAPTER:

1

8 Using the Database Tools

The Example Database

737 737 738 739 740

Database Painter The Database Painter bar Connecting to a Database

ODBC

741

Configuring

ODBC

741

745 747 749

Defining Database Profiles Connecting to a Database

Opening Tables Table Creation and Maintenance

751

Maintaining Tables

757 758 760

The

Activity

The

Six Edit Styles

Log Display Format Maintenance Edit Style Maintenance

761

DropDown DataWindows Validation Maintenance

Data Manipulation Database Administration Activity Logs Creating a Sybase SQL Anywhere Database The Data Pipeline

More on

A

ODBC

Brief

Look

at the

ODBC Architecture

ODBC Installation ODBC Administration ODBC Drivers Logic Work's ERwin for PowerBuilder Benefits of

Using ERwin

The ERwin Data Model ERwin and Normalization Client/Server Support

ERwin and the Application Design Process An ERwin Client/Server Example

CHAPTER:

1

9 Extending

DLLs Calling

DLL

Functions

TcstDLL Application

The DLL C++ Code

MQUE

Application

Windows API

Calls

PowerBuilder

762 764 764 766 768 769 771 771

775 776 776 777 777 784 785 785 786 786 787 793

787 807 808 810 817 823 825

Contents

DDE The DDE Process The Sample DDE Applications

DDE Window Events DDE Example

The

Global Function l_dde_row_column Global Function f_dde_pack_row_column

DDE Client DDE Seiner

The

OLE Appendix

A

827 828 830 835 835 835 836 836 840 844

849

Appendix B

867

Index

887

PREFACE

you would

If

your value

like to quickly increase

move you can make

at this time.

quickly as possible. to

demonstrate each

A will

book

is

probably the best

to bring developers,

to speed

who

on PowerBuilder

as

book

topic. This

number

a

of

will take

you through intermediate program-

advanced programming techniques. Then Appendix

help prepare fi=or the PowerBuilder Certification Exams.

This book

The

intent of this

is

uses a "by-example" approach, providing complete applications

It

ming and introduce

The

one other language up

are already proficient in at least

developer and

as a client/server

ensure your employability, becoming proficient with PowerBuilder

is

a complete introduction to PowerBuilder 5 and PowerBuilder Desktop.

book

material in this

been teaching

based on

is

for several years.

I

—and has been

believe that

as the best explanation. In this book,

I

well tested in

—seminars

working code examples

I

have

are as informative

present dozens of sample applications, each

focused on a particular area of PowerBuilder development. These examples are included

on the

CD-ROM

that

comes with

My goal is to get you up tion

you need

into

advanced

to

become

to

this

book.

speed as quickly as possible and to provide the informa-

a proficient PowerBuilder developer. This material extends

and on the advanced topics that

topics,

equal to or even

will find coverage that

is

PowerBuilder books.

you complete

If

this

more

I

think are most important, you

detailed than that of

some "advanced"

book, you will be a PowerBuilder developer.

Using this Book I

will present

dozens of sample applications, each focused on

a particular area of

PowerBuilder development. The examples have been carefully designed the essential areas of PowerBuilder development. cises

to

cover

all

have completed the exer-

based on these examples, you will have acquired hands-on experience with the

most important

details of

PowerBuilder and

Complete source code throughs for creating

may

When you

use the code

in

is

provided

for

will

have covered

many advanced

each of the examples, and

I

topics.

provide walk-

many of the examples. This edition includes a CD-ROM. You your own applications without limitation (except that you may

Preface

not use this code for another PowerBuilder book or training). The examples are also

intended to serve as a resource

development.

for future

Using the Example Applications The

CD-ROM

and

a

number

that

comes with

of other objects

bases, icons, text

files,

book contains

this

you

will

need

finished versions of

and so on). You should

first

create a similar application.

should attempt to create your

When

you need a

Most

of the

own

hint, refer to the text or

covered

have created

all

at least

and think about

of the options,

the application,

you

PowerBuilder development

When you

will

one of every type of object

in the

have completed

have acquired

the important aspects of PowerBuilder.

You

Window

It

is

highly

recommended

that

hands-

real,

will, for

example,

painten You will also

have a large amount of source code and example objects that you can reuse

PowerBuilder applications.

you

examine the example's code.

a particular area of

the exercise of duplicating each of the examples,

on experience with

all

Once you understand

the corresponding text).

in

(data-

version of the application (as closely as possible).

examples focus on

(relating to the area

the exercises

read the material presented before

each example application. Then run the example, try

how you would

all

example applications

to create the

you take time

in

to

your

work

through each example.

The PowerSoft Tools PowerSoft markets

a

number

of application tools for developing client/server

applications. PowerSoft has taken the lead in

end development systems, and importance. The

Watcom

its

market share

for client/server front-

merger with Watcom and Sybase has increased

compiler technology will help PowerBuilder to create

better-performing applications, and

Watcom and

Sybase's software

its

faster,

methodology and

experience will result in a more robust development environment. With these devel-

opments, PowerBuilder of client/server

The examples that

is

is

well positioned for growth and will remain in the forefront

development in this

tools.

book use the Sybase SQL Antwhere 5.0 database engine

included with both PowerBuilder and PowerBuilder Desktop. To run the

examples, you must have installed the databaseengine.

run the PowerBuilder installation and these examples.

install just

If

you did

not,

you should

the database engine, before running

Preface

PowerBuilder 5 PowerBuilder

is

a powerful object-oriented client/server front-end

development system

Windows (Unix Motif and Macintosh versions are also available). PowerBuilder is best known for its intuitive user interface, ease-of-use, object-oriented for

Microsoft

features,

and powerful high-level constructs. These features make development with

PowerBuilder highly productive. PowerBuilder

"data-centric."

is

a database application,

and

It

assumes from the beginning that you are creating

at every step

it

includes a great deal of intelligence about

creating a client/server front-end application. This

the main difference between

is

PowerBuilder and Visual Basic, and the productivity gain tions

is

application by creating PowerBuilder objects (such as

the various PowerBuilder Painter level construct that

object.

for client/server applica-

well worth making the switch to PowerBuilder. You define

windows and

much

PowerBuilder's Data Window object

utilities.

of your

controls) with is

a high-

encapsulates data access within an intelligent database-aware

Data Windows

are, in

many ways,

the essence of PowerBuilder's client/server

power. Basically the Data Window stands between your application and the database.

You is

will interact

with Data Windows

unsurpassed by the competition

for nearly

at the

all

of

your data access. The Data Window

moment.

PowerBuilder also creates and maintains

its

own

repository in the target data-

base system. This repository stores information about the tables, columns, indexes,

and so forth that are used by your applications. and define

certain table

EMP_NO

from the table

a

column heading, such

EMPLOYEE,

the next time you add that

column

implement standards

will help to

of your screens

and

reports.

that heading

to a report for the

You can

you specify

If

a default font for a

"Employee ID"

as

and font

will

(DataWindow)

for the

column

be used as the default

in

an application. This

database references and the appearance

and

also define validation rules, foreign keys,

soon.

The PowerBuilder

interface

point-and-click application

clearly the

second to none, as

company can

no Windows experience) up

short time

far as is

implementing

a graphical

concerned. PowerBuilder

most productive Windows development environment available

client/server development. Your

(with

is

development environment



just a

to

speed

bring

in

COBOL

mainframe programmers

PowerBuilder development

in a

couple of weeks of retraining. They can be productive

weeks and can reach an intermediate

level within a

is

for

in a

few months. But there

is

very

few

much

more

to client/server

must

also understand client/server architecture,

SQL, the event-driven paradigm,

some

object-oriented concepts, and collaborative

programming concepts including

development than

just learning the

PowerBuilder

tool.

I

You

Preface

standards, procedures, and methodology).

PowerBuilder takes

advantage of the event-driven

full

Windows environment

and provides database-independent development. The PowerBuilder objects you create

can contain program

execute in response to different events. You can

scripts that

develop applications against the local PowerBuilder) and then

(DBMS) such Sybase

move

Watcom

database engine (provided with

the application to another database

management system

or Oracle.

PowerBuilder contains

number

a

of object-oriented features that will greatly

increase the productivity of application development by providing reusable objects

and code and by allowing the use of well-structured applications. This that sets

it

off

from the competition, including Visual

is

another area

Basic.

PowerBuilder has an open architecture, and a number of third-party tools can be integrated into your development environment, including

control systems, and testing

CASE

tools,

source code

utilities.

Installing the Examples (See Appendix B)

CD-ROM

The

example

files

installing the

as

that

comes with

(all

and

it

further references

ODBC configuration C:\PB5\MCCLAN2 is the

will create the

assume

so adjust these statements according to the actual location

tory,

highly

Many

recommended

that

of the objects in the applications files. If

to adjust the path references in the

After installing the

example

C:\PB5\MCCLAN2)

and the application

you must

example files,

necessary for the installation direc-

you have chosen).

It is

install to

profile files

assume

this to

be

another directory, you will have

applications.

you must run the PBINI example program

from within PowerBuilder. This application will

update the LibList (the library search path) tions.

on

you accept the default directory (C:\PB5\MCCLAN2i.

the directory for the example

(found in

that will install the for instructions

examples. The setup program will create a directory for the examples, such

C:\PB5\MCCLAN2,

database

book includes a setup program

this

and database on your system. Read Appendix B

for the

example PowerBuilder

applica-

Appendix B has detailed information on PBINI.

All of the database examples use a Sybase SQL Anywhere 5.0 database C:\PB5\MCCLAN2\MCCLAN2.DB (and MCCLAN2.LOG). The install program can set up the ODBC configuration in most cases. The chapter on the Database painter, explains how to set up the ODBC configuration and the database profile if you need to

do

it

tells

by hand. Appendix B also includes a table that

you which examples go with which chapters.

lists

the example applications and

Preface

The examples have been

carefully designed to cover

all

the essential areas of

PowerBuilder development. You should run each example so that you understand exactly

what the

application does and

how

looks.

it

Next you should attempt

to

duplicate the example application as precisely as possible.

You should be able

each application from the knowledge you have

to create

gained by reading the text and using the PowerBuilder Help system.

If

you cannot

complete the exercise in that manner, open the example application and examine the source code.

It

would be

You can do

helpful to print out a listing of each application.

this in the Library painter.

Throughout

this

book,

C:\PB5\MCCLAN2.

If

we assume

that

is

that the path to the sample application

is

not the case (perhaps you placed them in directory

D:\pbsamplei, you will have to adjust all references to C:\PB5\MCCLAN2 The SETUP program will allow you to place the example files in any

accordingly. directory.

Additional Information Most

of the material in this

teaching over the

last

few

book

is

years.

I

based on the PowerBuilder seminars

development (beginning, intermediate, and advanced). other client/server and database-related topics.

you

find this

I

have been

teach three one-week seminars on PowerBuilder

Good

book and the example applications

I

useful.

I

on

also teach seminars

luck with PowerBuilder.

I

hope

can be reached via email

at

725 17.11 [email protected]. This method

may

also be available.

also

be licensed

Contact

me

for

for

PowerBuilder training

more information.

classes.

A workbook

will

CHAPTER

Introduction to PowerBuilder 5 This chapter presents an overview of the PowerBuilder environment and points out

important areas in which you must become fluent to be a PowerBuilder developer. This chapter provides an introduction to the following topics:

The PowerBuilder development environment

O

The online-help system The

context-sensitive

popup menu

The PowerScript language The

text

The

object browser

file

editor

DataWindows Object-oriented features of PowerBuilder Attributes, events, and functions

The PowerBuilder

painters

The Development Environment The PowerBuilder installation program adds a new program group named Powersoft to your Windows desktop. In the Powersoft program group, double-click on the icon labeled PowerBuilder 5.0 or PowerBuilder Desktop to launch the PowerBuilder .

application.

After you start the application, the Figure

the

1

.

1

shows the

PowerBar.

ilf

initial

the

initial

display format, a

Welcpme window opens

window is displayed. menu and a toolbar called

PowerBuilder

window with first

,

a

just close

it.)

Chapter

I:

Introduction to PowerBuilder 5

(Wrrl)uildei

pbini

«lwlrf|B|y|'jisp| Tij^iM