Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Beginning REALbasic - From Novice To Professional (2006)

.pdf
Скачиваний:
232
Добавлен:
17.08.2013
Размер:
18.51 Mб
Скачать

Beginning REALbasic

From Novice to Professional

■ ■ ■

Jerry Lee Ford, Jr.

Beginning REALbasic: From Novice to Professional

Copyright © 2006 by Jerry Lee Ford, Jr.

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

ISBN-13 (pbk): 978-1-59059-634-0

ISBN-10 (pbk): 1-59059-634-X

Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1

Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

Lead Editor: Chris Mills

Technical Reviewer: Allan Kent

Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,

Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser,

Keir Thomas, Matt Wade

Project Manager: Richard Dal Porto

Copy Edit Manager: Nicole LeClerc

Copy Editor: Marcia Baker

Assistant Production Director: Kari Brooks-Copony

Production Editor: Lori Bring

Compositor: Pat Christenson

Proofreader: Linda Seifert

Indexer: Broccoli Information Management

Artist: April Milne

Cover Designer: Kurt Krames

Manufacturing Director: Tom Debolski

Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com.

For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com.

The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.

The source code for this book is available on the accompanying CD. Any corrections to code and errata are posted for download/viewing at http://www.apress.com. Just search for the book by title, author, or ISBN, in the search bar on our homepage.

To Alexander, William, Molly, and Mary.

About the Author

Contents at a Glance

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

PART 1 ■ ■ ■ Introducing REALbasic

CHAPTER 1 An Introduction to REALbasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

CHAPTER 2 Navigating the REALbasic Integrated Development

Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

PART 2 ■ ■ ■ Learning How to

Program with REALbasic

CHAPTER 3 Creating an Application’s User Interface . . . . . . . . . . . . . . . . . . . . . . . 67

CHAPTER 4 Working with REALbasic Menus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

CHAPTER 5 Storing and Retrieving Application Data . . . . . . . . . . . . . . . . . . . . . . 135

CHAPTER 6 Making Decisions with Conditional Logic . . . . . . . . . . . . . . . . . . . . . 163

CHAPTER 7 Iterative Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

CHAPTER 8 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

PART 3 ■ ■ ■ Advanced Topics

CHAPTER 9 Processing Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

CHAPTER 10 Working with Databases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273

CHAPTER 11 Working with Graphics and Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

CHAPTER 12 Debugging REALbasic Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . 323

iv

PART 4 ■ ■ ■ Appendixes

 

APPENDIX A Migrating Visual Basic Projects to REALbasic . . . . . . . . . . . . . . . . .

347

APPENDIX B What’s on the CD-ROM? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

351

APPENDIX C What’s Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

353

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

357

v

About the Author

Contents

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

PART 1 ■ ■ ■ Introducing REALbasic

CHAPTER 1

An Introduction to REALbasic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 3

 

Overview of REALbasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

 

Drag-and-Drop GUI Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

 

Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

 

RAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

 

Cross-Platform Application Development . . . . . . . . . . . . . . . . . . . . . . .

6

 

What Can REALbasic Do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

 

What’s New in REALbasic? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

 

Supported Development Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . .

8

 

Supported Execution Platforms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

 

Standard vs. Professional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

 

REALbasic 2006 Standard Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

 

REALbasic 2006 Professional Edition . . . . . . . . . . . . . . . . . . . . . . . . .

12

 

Downloading REALbasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

13

 

REALbasic vs. Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

14

 

REALbasic vs. Apple’s XCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

 

Online REALbasic Support Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

17

 

Getting Started with Your First REALbasic Application. . . . . . . . . . . . . . . .

19

 

Hello World! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

19

 

Compiling Your Application for Macintosh, Windows, and

 

 

Linux Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32

 

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

33

vii

viii

C O N T E N T S

 

 

 

CHAPTER 2

Navigating the REALbasic Integrated Development

 

 

 

Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

 

 

Starting REALbasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

 

 

The REALbasic Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

37

 

 

REALbasic’s Main Toolbar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

38

 

 

Default Main Toolbar Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

38

 

 

Configuring REALbasic’s Main Toolbar . . . . . . . . . . . . . . . . . . . . . . . .

38

 

 

REALbasic’s Bookmarks Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

39

 

 

Adding New Bookmarks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

40

 

 

Editing Your Bookmarks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

40

 

 

REALbasic’s Screen Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

41

 

 

Tabs Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

41

 

 

Editor Toolbar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

42

 

 

Screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

42

 

 

REALbasic’s Tips Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51

 

 

REALbasic’s Integrated Help Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

52

 

 

Accessing REALbasic’s Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

53

 

 

Accessing REALbasic Online Resources . . . . . . . . . . . . . . . . . . . . . . .

53

 

 

Working with REALbasic’s Electronic Language Reference. . . . . . .

54

 

 

Building a Custom Web Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

57

 

 

The RBBookFinder Browser. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

58

 

 

Designing the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

 

 

Changing Windows and Control Properties . . . . . . . . . . . . . . . . . . . .

61

 

 

Adding a Little REALbasic Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

62

 

 

Testing Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

63

 

 

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

64

 

PART 2 ■ ■ ■ Learning How to

 

 

 

Program with REALbasic

 

 

CHAPTER 3

Creating an Application’s User Interface. . . . . . . . . . . . . . . . . .

67

 

 

Building Application Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

67

 

 

Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

69

 

 

Movable Modal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

69

 

 

Modal Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

70

 

 

Floating Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

70

 

 

Plain Box Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

71

 

 

Shadowed Box Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

72

C O N T E N T S

ix

Rounded Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Global Floating Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Sheet Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Metal Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Drawer Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

Changing the Default Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Deleting Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Encrypting and Decrypting Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Working with Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Adding Controls to Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Finding Lost Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Modifying Control Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Deleting Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 A REALbasic Control Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 The BevelButton Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 The Canvas Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 The CheckBox Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 The ComboBox Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 The ContextualMenu Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 The DatabaseQuery Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 The DataControl Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 The DisclosureTriangle Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 The EditField Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 The ExcelApplication Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 The GroupBox Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 The HTMLViewer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 The ImageWell Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 The Line Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 The ListBox Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 The MoviePlayer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 The NotePlayer Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 The OLEContainer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 The Oval Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 The PagePanel Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 The Placard Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 The PopupArrow Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 The PopupMenu Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

The PowerPointApplication Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

The ProgressBar Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 The ProgressWheel Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89