I have created 3 calcfields in a table. They are credit, debit and balance.
The on calcfield event of the table is to set the amount in the record to either debit and credit based on the entry in the type field.
The balance is then incremented based on the credit value and reduced based on the debit value.
This worked fine on an un-filtered dataset.
However, when tried on a filtered dataset, it gives strange results. Basically, it appears to be calculating the balance field before applying the filter to the table that returns the filtered dastaset.
How do I overcome this, i.e. can I controll the filtering of the table before oncalcfields calculates the balance.
Below is the code i'm using :
Procedure Tform2.TableCalcFields(Dataset: TDataset);
begin
//place amount in debit or credit field
if table2Type.text = 'Debit' then
table2Debit.text := table2Amount.text;
else
table2Credit.text := table3Amount.text;
//calculate the balance field
table2Balance.asInteger := aBal +
table2Credit.asInteger - table2Debit.asInteger;
aBal := table2Balance.asInteger;
end;
//aBal is declared as a public variable and assigned a value in the before open event of table2
procedure TLedger.Table2BeforeOpen(DataSet: TDataSet);
begin
aBal := 0;
end;
I've ommited the filtering procedure.
Very long. I'm sorry. Please help.
yomyom.
The on calcfield event of the table is to set the amount in the record to either debit and credit based on the entry in the type field.
The balance is then incremented based on the credit value and reduced based on the debit value.
This worked fine on an un-filtered dataset.
However, when tried on a filtered dataset, it gives strange results. Basically, it appears to be calculating the balance field before applying the filter to the table that returns the filtered dastaset.
How do I overcome this, i.e. can I controll the filtering of the table before oncalcfields calculates the balance.
Below is the code i'm using :
Procedure Tform2.TableCalcFields(Dataset: TDataset);
begin
//place amount in debit or credit field
if table2Type.text = 'Debit' then
table2Debit.text := table2Amount.text;
else
table2Credit.text := table3Amount.text;
//calculate the balance field
table2Balance.asInteger := aBal +
table2Credit.asInteger - table2Debit.asInteger;
aBal := table2Balance.asInteger;
end;
//aBal is declared as a public variable and assigned a value in the before open event of table2
procedure TLedger.Table2BeforeOpen(DataSet: TDataSet);
begin
aBal := 0;
end;
I've ommited the filtering procedure.
Very long. I'm sorry. Please help.
yomyom.