Re:Keeping a BALANCE using a DBGrid - HELP!
Quote
Dan Cusic <cu...@evansville.net> wrote:
>I have a dBase Table we use to track all inflows and outflows. I am
>converting my dBaseIV program to view this Table with extra info and a
>BALANCE column to Delphi. I have been using DBGrids like crazy in my
>other apps, so my first thought is to use that. But I have not been able
>to show the Balance on the same line as the corresponding record.
>Example:
> Payment Receivable BALANCE
> 255.00 255.00
> 325.00 580.00
> 400.00 180.00
> ETC....
>I have tried using Calculated fields, but, since I need to move off the
>current record to set the value for this record, it never works. I'm
>trying to avoid creating a scroll-able grid-like interface to do this,
>and I know LOTS of apps require that a running-total is taken, so is
>there an option I'm overlooking to get this done (besides adding a
>BALANCE field to my DBF, which causes major problems to maintain correct
>balances for each record each time an edit, addition, or deletion is
>made!!) I considered leaving a blank field and have it calculate it
>everytime the program starts, but there are over 100,000 records!!
>Definitely not an option!! HELP!!!
One thing you might try is having an additional TTable or TQuery component
that references the same table as the TDBGrid is connected to. This way,
you can perform these multi-record aggregate operations in the secondary
TTable without moving the record pointer in the TTable supplying data to
the TDBGrid.
A TQuery might be used to return a summary of the data. It would require a
parameter of the key field value that identifies the current record, and
performs a SELECT with a SUM operation, using the parameter value in the
WHERE clause so it only operates on matching records. In the OnCalcField
event procedure, you can then activate the TQuery and store into the
calculated field for the current record the "field" value returned by the
TQuery.
However, running a query for *each* record would probably be so inefficient
as to be impractical. From a performance perspective, it would likely be
better to use a secondary TTable rather than the TQuery, and perform the
aggregate operation manually.
**************************************************************************
Steve Koterski
Local InterBase Server Technical Support
Borland International, Inc.