Subject Re: [IBO] Aggregate functions of a Live TIB_Grid?
Author Helen Borrie
At 11:12 PM 12-03-01 +0100, you wrote:
>I have a TIB_Grid for insert and update records, and I would show on the same form a virtual, calculated field (read-only, as a simple Label), that accumulates the total amount of all records.
>For example:
>ID SMALLINT (with generator) PRIMARY KEY
>It's to say, I need something like
>and everytime table SALES changes, it calculates again; but I think it's no good using another TIB_Query for this total_amount, because following reasons:
>- the records I insert at this "session" don't exist on the server until I commit transaction or close my application.
>- I guess this solution makes bad performance, because there is two open ways working with the same data.

Performance isn't really the issue - if you wanted the column to aggregate each time you commit, it won't hurt performance at all to have both queries inside the same transaction with the output of the second query in a TIB_Edit. It can just Refresh when you commit the changes to Sales.

The issue is that you want your total to reflect user input *before* the changed rows commit.

>So, is there some feature that allows operating with aggregate functions over a "buffered dataset" which is entirely on the client side?

Yes, it's called an event handler. :))

Just drop an ordinary TEdit on your form and position it at the bottom of the column. Write a handler for the DataChange event of the TIB_DataSource that responds appropriately to the IsModified property of either of the columns (passed to the handler as Field) involved in the aggregation.

You might find it useful to employ the aggregate query to bring an initial total into the application and load/refresh an underlying variable, which your handler will update when a data change occurs in one of these columns.


All for Open and Open for All
InterBase Developer Initiative ยท