Hackers Guide to Visual FoxPro 7.0
Alias, Exclusive, Filter, Order, ReadOnly
These are all properties of a cursor in the Data Environment of a form, report or label. They let you indicate how the table or view the cursor refers to is to be opened. These properties affect a table or view only if it is opened by the Data Environment, either because AutoOpenTables is .T. or by explicitly calling the OpenTables method. If the table or view is opened in other code, it uses the settings in the USE command and the current SET settings. ReadOnly also applies to several controls and to the Project's File object.| Usage | frmForm.DataEnvironment.crsCursor.Alias = cAlias cAlias = frmForm.DataEnvironment.crsCursor.Alias |
| Usage | frmForm.DataEnvironment.crsCursor.Exclusive = lIsExclusive lIsExclusive = frmForm.DataEnvironment.crsCursor.Exclusive |
| Usage | frmForm.DataEnvironment.crsCursor.Filter = cFilterString cFilterString = frmForm.DataEnvironment.crsCursor.Filter |
| Usage | frmForm.DataEnvironment.crsCursor.Order = cTagName cTagName = frmForm.DataEnvironment.crsCursor.Order |
| | There's no way to turn off index order. That is, you can't restore the table to natural order by modifying the Order property. We can't even think of a work-around that restores natural record order—ResetToDefault doesn't work. (In fact, you can't reset Order to default in the property sheet, either. How odd!) |
| | Okay, so we lied. We can think of a way to restore natural record order, but the cure may be worse than the disease. You can SET ORDER TO and the table is displayed in natural order. However, the cursor's Order property still reflects the last order you specified. (Fortunately, ORDER() does correctly return the empty string.) |
Bottom line: If you need to work with records in natural order, you may want to stay away from the Order property in code. Use it in the property sheet to set the initial table order, but make all your changes with SET ORDER and do all your testing with ORDER(). (Of course, the main reason to use natural order is because it's faster for some operations.)
We should probably explain why we say that Order affects views. Although views can't have index tags stored for them, you can index a view once it's open. One clever trick is to force OpenTables to open the tables and views prematurely (see DoDefault() for details), then create some index tags for your views. Starting in VFP 7, you can use the AfterOpenTable database event to index a view once you've opened it. Once you've created the tags, you can set Order just as you can for a table.| | In VFP 7, if you create tags for a view in the AfterOpenTable event, you can set Order to one of those tags in the Property Sheet. Of course, the tags don't appear in the dropdown, but you can just type in the tag name you want. |
Prior to VFP 7, you can't set Order for a view in the property sheet—that value gets called on too soon.
| Usage | frmForm.DataEnvironment.crsCursor.ReadOnly = lIsReadOnly lIsReadOnly = frmForm.DataEnvironment.crsCursor.ReadOnly |
| Example | * The following assumes you've added the TasTrade * Customer table to the DE of a form as the first table, * so the corresponding object is named "Cursor1". * You'd normally set these properties in the Form Designer, * but here's the code: ThisForm.DataEnvironment.Cursor1.Alias="Cust" ThisForm.DataEnvironment.Cursor1.Exclusive=.T. ThisForm.DataEnvironment.Cursor1.Filter="country='USA'" ThisForm.DataEnvironment.Cursor1.Order="company_na" ThisForm.DataEnvironment.Cursor1.ReadOnly=.F. |
| See Also | AfterOpenTable, Alias(), Cursor, DataEnvironment, DoDefault(), Enabled, File, Filter(), IsExclusive(), IsReadOnly(), Order(), ResetToDefault, Set Exclusive, Set Filter, Set Order, Use |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.
Категории