I hope you're using a clientdataset for that as writing all that to disk sounds 
incredibly slow. Clientdataset has the ftInternalCalcField which can be written 
to. Perfect for that sort of thing.

Dave

--- On Thu, 10/23/08, Nesler, Thomas J <[EMAIL PROTECTED]> wrote:
From: Nesler, Thomas J <[EMAIL PROTECTED]>
Subject: RE: [delphi-en] DBGrid and calculated fields
To: [email protected]
Date: Thursday, October 23, 2008, 6:49 AM










    
            I have found the OnCalcfields event to be triggered way too often 
for

this kind of work.  I created two fields in my checkbook program;

PrevBal and Balance.  I use a procedure called RecalcBalance to run

through the checkbook table calculating the two fields.



On each record, I take the previous balance (which I save in a variable)

and post it into the PrevBal field and then calculate the Balance field.

Because checks can be dated into the future, once the current date is

reached, I change the Balance field amount to zero.



Hope this helps you!...:-)



Tom Nesler



-----Original Message-----

From: [EMAIL PROTECTED] ps.com [mailto:[EMAIL PROTECTED] ps.com] On

Behalf Of Ian Stewart

Sent: Thursday, October 23, 2008 4:13 AM

To: [EMAIL PROTECTED] ps.com

Subject: [delphi-en] DBGrid and calculated fields



Hi!



I have a problem with a project I am working on. I have a database

table containing financial transactions:



id    account    date    description    amount_in    amount_out



I filter the table based on things like account, date ranges etc and

then show the results in a DBGrid. The user can click on a column to

change the sort. I need to show the current balance on each row so:



balance = previous_balance + (amount_in - amount_out)



This isn't a big problem until the user scrolls the grid or changes

the sort field, then the balance column changes as the balance on the

previous row is wrong.



There are only two solutions I can think of:



Add a balance field to the table and update it as needed, which is

fine until the user modifies a very early transaction and has to wait

as all the more recent ones are updated.



The other idea is to do a select statement to calculate the balance of

all the transactions that has an earlier date of the row being

processed. This is great for a few dozen rows but really slow when

there are thousands of rows to display.



I would really appreciate any other ideas or comments.



------------ --------- --------- ------



------------ --------- --------- --------- --------- -----

Home page: http://groups. yahoo.com/ group/delphi- en/

To unsubscribe: delphi-en-unsubscri [EMAIL PROTECTED] comYahoo! Groups Links




      

    
    
        
         
        
        








        


        
        


      

[Non-text portions of this message have been removed]

Reply via email to