MapBasic User Guide.pdf

(2907 KB) Pobierz
MapBasic User Guide
MapBasic
Version 9.0
USER GUIDE
652906338.001.png
Information in this document is subject to change without notice and does not represent a commitment on the part of the vendor or its representatives. No part of this document
may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, without the written permission of MapInfo Corporation,
One Global View, Troy, New York 12180-8399.
© 2007 MapInfo Corporation. All rights reserved. MapInfo, the MapInfo logo and MapBasic are trademarks of MapInfo Corporation and/or its affiliates.
MapInfo Corporate Headquarters:
Voice: (518) 285-6000
Fax: (518) 285-6070
Sales Info Hotline: (800) 327-8627
Government Sales Hotline: (800) 619-2333
Technical Support Hotline: (518) 285-7283
Technical Support Fax: (518) 285-6080
Contact information for all MapInfo offices is located at: http://www.mapinfo.com/contactus.
Adobe Acrobat® is a registered trademark of Adobe Systems Incorporated in the United States.
Products named herein may be trademarks of their respective manufacturers and are hereby recognized. Trademarked names are used editorially, to the benefit of the
trademark owner, with no intent to infringe on the trademark.
May 2007
Table of Contents
Chapter 1: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Hardware & Software Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
Compatibility with Previous Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
Installing the MapBasic Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . .14
Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
Starting MapBasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
MapBasic File Names and File Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
MapBasic Documentation Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16
MapBasic® Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16
Installing Online Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16
Conventions Used in This Manual. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Register Today! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Working with Technical Support. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Before You Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
The Support Tracking System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Expected Response Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Exchanging Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Software Defects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Other Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Chapter 2: New and Enhanced MapBasic Statements and Functions . . . . . . . . 21
New in MapBasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22
Enhanced Functions and Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
LabelClause Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
Layer Activate clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42
Adding New HotLink Definitions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
Modifying Existing HotLinks Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
Removing HotLink Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Reordering HotLink Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Exceptions to Support Backwards Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
User Guide
3
652906338.002.png
Table of Contents
Chapter 3: A Quick Look at MapBasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48
How Do I Create and Run a MapBasic Application? . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
What Are the Key Features of MapBasic? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
MapBasic Lets You Customize MapInfo Professional . . . . . . . . . . . . . . . . . . . . . . . . . . 49
MapBasic Lets You Automate MapInfo Professional. . . . . . . . . . . . . . . . . . . . . . . . . . . 49
MapBasic Provides Powerful Database-Access Tools . . . . . . . . . . . . . . . . . . . . . . . . . 50
MapBasic Lets You Connect MapInfo Professional to Other Applications . . . . . . . . . . 50
How Do I Learn MapBasic? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
The MapBasic Window in MapInfo Professional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Training and On-Site Consulting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Chapter 4: Using the Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . 53
Introduction to MapBasic Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . 54
Editing Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Limitations of the MapBasic Text Editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Compiling Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
A Note on Compilation Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Running a Compiled Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Using Another Editor to Write MapBasic Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Linking Multiple Modules Into a Single Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
What is a MapBasic Project File? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Creating a Project File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Compiling and Linking a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Calling Functions or Procedures From Other Modules . . . . . . . . . . . . . . . . . . . . . . . . . 62
Menu Summary in MapBasic Development Environment. . . . . . . . . . . . . . . . . . . . . . . 64
The Edit Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
The Search Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
The Project Menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
The Window Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
The Help Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Chapter 5: MapBasic Fundamentals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
General Notes on MapBasic Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Case-Sensitivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Continuing a Statement Across Multiple Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Codes Defined In mapbasic.def. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Typing Statements Into the MapBasic Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71
Fixed-length and variable-length String variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4
MapBasic 9.0
652906338.003.png
Table of Contents
Array Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
Custom Data Types (Data Structures) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74
Global Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75
Scope of Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76
What is a Constant?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76
What is an Operator? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77
What is a Function Call? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77
A Closer Look At Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .78
Variable Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81
A Closer Look At Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81
MapBasic Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .85
Looping, Branching, and Other Flow-Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86
If…Then Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86
Do Case Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87
GoTo Statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88
For…Next Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88
Do…Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
While…Wend Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
Ending Your Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
Ending Your Program and MapInfo Professional. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
Main Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
Calling a Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
Calling a Procedure That Has Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
Passing Parameters By Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
Passing Parameters By Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
Calling Procedures Recursively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
Procedures That Act As System Event Handlers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
What Is a System Event?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .94
What Is an Event Handler? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .94
When Is a System Event Handler Called? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96
Tips for Handler Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Keep Handler Procedures Short . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Selecting Without Calling SelChangedHandler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Preventing Infinite Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Custom Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Scope of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
Compiler Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
The Define Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
The Include Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
Program Organization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100
User Guide
5
652906338.004.png
Zgłoś jeśli naruszono regulamin