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] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Stewart Sent: Thursday, October 23, 2008 4:13 AM To: [email protected] 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: [EMAIL PROTECTED] Groups Links

