Topic: Application crash

Hi Guys,
After trying to add new record I get app crass

https://images2.imgbox.com/4b/c0/TB0As9hK_o.png

Here is the script. Disabled script line (Tax Calc) is causing the crash and I cannot spot the script error?

procedure CalculateTotal;
var
TaxRate:double;
begin
TaxRate := 0;
frmRevenue.edAfterExp.value := frmRevenue.edGrossAmt.value - frmRevenue.edLessExp.value;
TaxRate := sqlexecute('select TaxRate from TaxRates where id = '+frmRevenue.cbTaxRate.sqlvalue);
//frmRevenue.edTaxAmt.value := frmRevenue.edGrossAmt.value * (TaxRate / 100);
frmRevenue.edNetAmtRecvd.value := frmRevenue.edAfterExp.value - frmRevenue.edTaxAmt.value;
end;

// CALC EVENTS
procedure frmRevenue_edGrossAmt_OnChange (Sender: string);
begin
CalculateTotal;
end;

procedure frmRevenue_edLessExp_OnChange (Sender: string);
begin
CalculateTotal;
end;

procedure frmRevenue_edTaxAmt_OnChange (Sender: string);
begin
CalculateTotal;
end;
Adam
God... please help me become the person my dog thinks I am.

2 (edited by CDB 2022-03-15 09:18:11)

Re: Application crash

Is Tax rate actually being filled? Try changing  Tax from a double to (temporarily) Int or Var putting in a

TaxRate := sqlexecute('select TaxRate from TaxRates where id = '+frmRevenue.cbTaxRate.sqlvalue);
showmessage((InttoStr(taxrate));

or "varToStr


If TaxRate is not getting data assigned your next line will fail as you would be dividing zero by 100 (0/100) which will cause an error.  The declaration of Tax as a double might also be causing a problem in MVD

On a clear disk you can seek forever

Re: Application crash

Hi CDB,
Thank you very much for your help. I could't apply it successfully tho.
Perhaps you or anybody else could apply the solution to the attached sample project.

Post's attachments

Attachment icon Tester3.zip 7.32 kb, 44 downloads since 2022-03-15 

Adam
God... please help me become the person my dog thinks I am.

Re: Application crash

Hi Adam,
You could try it like this (see attached) although personally I'd be using calculated fields to avoid the data redundancy.
Regards,
Derek.

Post's attachments

Attachment icon Tester3a.zip 339.36 kb, 52 downloads since 2022-03-15 

Re: Application crash

Hi Derek,
Thank you sooooo much for the solution......
I'm very glad that you are around.
If and when you have time I'd love to see your calculated fields solution too.

Adam
God... please help me become the person my dog thinks I am.