Hi all,
I am creating an book-keeping application. I have come up against a persistent error that I do not seem to be able to solve. The error appears to be in the procedure below. The app compiles correctly and when I attempt to open a Tdbf table I receive a SIGSEV fault within Lazarus and an Access Violation when the app is run outside it.
The procedure source is below.
procedure TMainForm.AdjustTotals;
var
f,g : Currency;
begin
f := 0;
g := 0;
if MyDbf.Active = True then
begin
try
MyDbf.DisableControls;
try
MyDbf.First;
while not MyDbf.EOF do begin
if MyDbf.FieldByName('Type').AsString = 'Credit' then f := f + MyDbf.FieldByName('Amount').Value;
if MyDbf.FieldByName('Type').AsString = 'Debit' then g := g + Mydbf.FieldByName('Amount').Value;
MyDbf.Next;
end;
finally;
MyDbf.EnableControls;
end;
except
end;
RecordsLabel.Caption:= IntToStr(MyDbf.RecordCount);
CreditLabel.Caption:= CurrToStr(f);
DebitLabel.Caption:= CurrToStr(g);
TotalLabel.Caption:= CurrToStr(f + g);
end
else
begin
RecordsLabel.Caption:= '0';
CreditLabel.Caption:= '00.00';
DebitLabel.Caption:= '00.00';
TotalLabel.Caption:= '00.00';
end;
end;
If the procedure statements are commented out within the app then there isn't an error, it's just when the table is opened. Strangely, when a new entry is posted to the table and the AdjustTotals procedure is invoked there is also no error.
Could someone look over the procedure with a fresh pair of eyes and point me in the right direction?
Thanks,
Tim.
_________________________________________
procedure TMainForm.AdjustTotals;
var
f,g : Currency;
begin
f := 0;
g := 0;
if MyDbf.Active = True then
begin
try
MyDbf.DisableControls;
MyDbf.First;
while not MyDbf.EOF do
begin
if MyDbf.FieldByName('Type').AsString = 'Credit' then f := f +
MyDbf.FieldByName('Amount').Value;
if MyDbf.FieldByName('Type').AsString = 'Debit' then g := g +
Mydbf.FieldByName('Amount').Value;
MyDbf.Next;
end; {MyDbf is EOF}
MyDbf.EnableControls;
finally;
MyDbf.EnableControls;
except
On {insert condition of exception – Es. EconvertError or EDBErrorr ….. } do {SomeThing}
end;
RecordsLabel.Caption:= IntToStr(MyDbf.RecordCount);
CreditLabel.Caption:= CurrToStr(f);
DebitLabel.Caption:= CurrToStr(g);
TotalLabel.Caption:= CurrToStr(f + g);
end {of MyDBF =True}
else
begin
RecordsLabel.Caption:= '0';
CreditLabel.Caption:= '00.00';
DebitLabel.Caption:= '00.00';
TotalLabel.Caption:= '00.00';
end;
end;