Subject Using TIB_TransactionBar
Author Russell Belding
Here is a note which may save new IBO users time. Below the note are some
quesions and comments for Jason on transactions. I suggest you check later
for corrections to my note here as more experienced IBO users may add
corrections.

If you are using IB_transactions to accumulate changes into work packages
and asking users to commit or rollback the work package this note may be
useful to you.

Suppose you have a Delphi form with a [Commit] and [Rollback] or equivalent
buttons on the form. You want the buttons to be enabled when changes are
made to your data when these changes you consider part of a unit of work.

A simple way to do this is use a single transaction on the form and have all
the IBO data components on the form use this transaction. Put an
IB_TransactionBar on the form and show only the CommitRetaining and
RollbackRetaining buttons. When they are enabled your users can Commit or
Rollback the changes they have made. You can read about the
IB_transactionBar in IBO help. You should have AutoCommit false in your
transaction, otherwise each change made is committed when made, and the
[Commit], [Retaining] buttons will not be used.

There is an adjustment you should make if you are using
IB_Transaction.StartTransaction. When this function is called the
CommitRetaining and RollbackRetaining buttons are enabled. This function can
possibly be avoided if you are using the method described above. If you need
it you need to surround it with logic to avoid giving a message that a
change has been made if a change has not been made.

There is another adjustment to may want to make. If you use an IB_ComboBox
and your user re-selects the current choice the IB_TransactionBar buttons
(as set up above) will be enabled, even though, from the users perspective
no change was made. You can work around this by writing event handlers for
the IB_ComboBox OnDropDown and OnChange event handlers. Logic that works is
like this. If a change was made ignore it in the OnChange event handler. If
a change was not made and if the IB_TransactionBar buttons are not enabled
then do a RollbackRetaining in the OnChange event handler. I have replaced
each IB_ComboBox with an IB_LookupCombo.

There may be other adjustments to make if within your form you do something
on the server that you regard as part of a work package, without going
through a component on your form which uses your IB_Transaction.

Suppose a part of the work you want to accumulate in the IB_Transaction is
done using a stored procedure. If you use an IB_DSQL for example then set
its IB_Transaction property to the form's transaction and the
IB_TransactionBar will catch a change. If you use a stored procedure for a
database task which you know results in no change to the work package then
set the IBDSQL.IB_Transaction property to IB_TRANSACTION(nil) so the
IB_TransactionBar will not accumulate the database action. IBO will use a
default transaction for the procedure. ( I am not sure of this - is this the
way to set an IB_Transaction property to a default value?)

Finally, you may want to replace the IB_TransactionBar buttons with your own
buttons. For example I use buttons like [ X Reject ] and [ (check) Accept ]
in place of the IB_TransactionBar buttons. One way this can be done is to
change the glyph on each IB_TransactionBar button and add a Caption to each
button. If you want to have Accept and Reject buttons physically separated
you could place a IB_Transactionbar on your form, hide the buttons and use
its OnButtonStateChanged event. In the event handler use
MyAcceptRejectButton.Enabled :=
IB_transactionBar.buttons[tbCommitretaining].Enabled. If you make the
IB_TransactionBar invisible its buttons will not be enabled or disabled.

Some questions and comments for Jason:

1. Is the correct way to specify a default transaction to make it
IB_Transaction(nil)?

2. When a transaction MyTr is programatically started by
MyTr.StartTransaction an associated IBTransactionBar has buttons
CommitRetaining, RollbackRetaining (and others) enabled. I am thinking these
buttons say "You have done work which is available to be committed or
rollbacked." and would prefer the buttons not be enabled at
StartTransaction. Perhaps there is another way to look at this.

3. It wold be desireable to have the IB_ComboBox not trigger a dssEdit
state whe the current value is reselected. However, one can avoid using the
IB_Combobox altogether by making a table with its items and using a
IBLookupcombo component. But this adds complexity.



Regards

Russell Belding