<< Click to Display Table of Contents >> Navigation: Apollo VCL Components > Installing and Using Apollo VCL > Setting relations between tables with Apollo |
If you are using a structural (aka maintained) index format, such as the FoxPro .CDX or HiPer-SIx .NSX format, you can set a relation in the exact same way as you would with Delphi's own dBASE .MDX files – using TApolloTable's MasterFields, MasterSource, and IndexName properties.
If you are using the Clipper .NTX index format, with the ttSXNTX TableType, the TApolloTable.IndexName and related properties listed above cannot be used. Instead, you would need to set up your index files using TApolloTable's ExtraIndexes property.
With any Apollo index format, you can also set relations using TApolloTable's SetScope method. This method is similar, but not exact, in behavior to TTable's own SetRange method. By setting the scope within the child (detail) table based on the value of the related field of the parent (master) table, the relation is maintained. Change/set this scope value by adding the code into the parent table's TDataSource.OnDataChange event.
TApolloTable's SetRelation method should only be used when doing 1-to-1 or Many-to-1 relations, but not for 1-to-Many relations. In all cases, the TApolloTable SetScope method is preferred for the following reasons:
•Using SetRelation, any data-aware controls will not be automatically refreshed during updates or record pointer movements without also using calls to TApolloTable's.UpdateCursorPos and Refresh methods. SetScope does not have this problem.
•If you attempt to use SetRelation on a 1-to-Many relationship, although the child table pointer would be accurately positioned on the first record in the child table to match the relation, it is not prevented from being moved above or below these matching records. With SetScope, it is not possible to scroll outside of the matching set.
See the ..\Samples\Relate subdirectory for four sample projects demonstrating each of these techniques.