CursorSource, Database
These two properties
belong to cursors in the DataEnvironment. They determine what
table or view the cursor references. CursorSource contains some
version of the name of the table or view—the name used depends on
whether it's a table or view and, for tables, whether it's free
or contained in a database. (See Help for the details.) Database
contains the full path to the database containing the table or
view, if the cursor isn't a free table.
Usage
|
curCursor.CursorSource = cName
cName = curCursor.CursorSource
curCursor.Database = cFullyPathedFileName
cFullyPathedFileName = curCursor.Database
|
Being able to change these properties, especially
Database, at runtime is important. By changing Database, you can
change a form from using last year's data to this year's, or from
using one client's to another's, or from using local data to
remote. Changing CursorSource seems less common to us.You can
make these changes in the DataEnvironment's OpenTables method. To
our pleasant surprise, although the objects involved haven't been
Init-ed yet, the changes stick and do affect the initial
automatic opening of tables. Keep in mind that doing it in
OpenTables means it'll happen every time you call that
method.Don't change these while the tables are open—you'll get an
error. Instead, call CloseTables to close them, make the changes,
and then call OpenTables to reopen them.If you want to choose a
database based on a parameter to the form, you can't use all of
the automatic table-opening features of the form. That's because
OpenTables occurs before all other events (even Form.Load and
more importantly, Form.Init, which receives parameters), when
AutoOpenTables is .T. In this case, you can set AutoOpenTables to
.F., and, in the form's Init, set Database for each cursor (think
SetAll), then call OpenTables. Unfortunately, this means you
can't bind controls to the table data at design-time. You may
want to consider using a "global" property, such as
oApp.cDataDirectory, to point to the data. Then you can set the
Database property of cursors in the form's Load.
Example
|
* Point a cursor to the already open and current database.
ThisForm.DataEnvironment.curCustomer.Database = DBC()
|
Back to Table of Contents
Copyright © 2002-2018 by Tamar E. Granor,
Ted Roche, Doug Hennig, and Della Martin. Click for license
.