Step 5. Customizing master-detail mechanism.
FIBPlus also allows setting some peculiarities of master-detail mechanism work. As you remember in particular in our example we have opened the detail-dataset (pFIBDataSet2) manually. It is simple if we deal with a simple link, but if we use several master-detail links or longer links (master-detail-subdetail), manual opening of all queries can cause an error. You must always open a detail query after the main one. For avoiding unnecessary coding TpFIBDataSet contains a special DetailOptions property:
Figure 15.
If setting the dcForceOpen key we can be completely sure that the detail-query will be automatically open after opening the master-query. Now we can delete the pFIBDataSet2.Open string form our program. Whatever the complexity of master-detail links is, all the queries will be open in the necessary order.
The second important option is the dcWaitEndMasterScroll key. Imagine that a user is navigating on DBGrid1 trying to find a necessary department. With each his movement when the current record in DBGrid1 changes, pFIBDataSet2 automatically reopens the query. It is obvious that navigation on the master-table will cause a number of rather complex queries, which will considerably increase the net-traffic. In practice we needed to reopen the detail-query only once when the user has finally found the department in DBGrid1. FIBPlus helps to avoid redundant queries. If the dcWaitEndMasterScroll key is added to DetailConditions, the detail-query will reopen only after some interval (the interval value can be regulated by setting values of WaitEndMasterInterval).
Thus when the user simply navigates on DBGrid1, the change of the current record activates the timer of the detail-query. If during the interval the user has time to pass on to another record, the timer will be restarted. This will happen until the user stops on the necessary record. The detail query reopens only after this and that means that pFIBDataSet2 executes only one query instead of a series of them.
Conclusion
Now you know how FIBPlus master-detail links work, how to connect to the database, execute a select query and generate modifying ones, work with data in the context of two transactions and link master and detail datasets. Though the described approach is very simple we recommend you to study the examples thoroughly.
|