Subject Re: [IBO] AfterInsert - Buffer Problem ?
Author Helen Borrie
At 05:10 PM 15/07/2005 +0000, you wrote:
>I have a query 'OfferDetails' with a MasterSource 'OfferHeader'
>where the BeforeInsert Event looks like this:
> iqOfferDetails.Last;
> if iqOfferDetails.FieldByName('AUTO_ID').AsInteger >= 1 then
> iOfferPos := iqOfferDetails.FieldByName('AUTO_ID').AsInteger + 1
> else
> iOfferPos := 1;
>and the AfterInsert Event:
> iqOfferDetails.FieldByName('AUTO_ID').AsInteger := iOfferPos;
>then the Post Method is called manualy by the UpdateBar-PostButton.
>Increasing the Details Positions this way works fine only
>up to exactly the second insert -
>then the iqOfferDetails.Last Method don't point to the latest entered
>record - instead to the previous one !
>For me it looks like either the post is not done or the data
>is not correctly re-read or similar.
>I also tried to insert an iqOfferDetails.InvalidateRows;
>before the iqOfferDetails.Last; command but it does not
>help ...
>Any ideas on where I am wrong ???

I'm nervous about what you are doing this for...but the main problem here
seems to be that you expect Insert to add the new row *after* the current
row. It doesn't. Insert adds it *before* the current row. So, if the
cursor is positioned on the last row, then the new row will not be be the
last row in the buffer, but the second-last. The original "last" row will
still be the last one.

If your actual intention is to *append* the new row to the end of the
buffer, then call Append, not Insert. That will cause the cursor to move
to EOF (which is *not* the same as Last) and add the new row to the end of
the buffer.

Because it's not clear in your description whether your transaction is set
to Autocommit or not, don't forget that Post only updates the table. It
won't be permanent until the transaction has been committed.

Once the work is committed, you can refresh the dataset. You can decide on
the position of the cursor after the refresh by setting the appropriate