Recent

Author Topic: TDbf Access Violation  (Read 4862 times)

WibblyTim

  • New Member
  • *
  • Posts: 46
    • http://www.wibblytim.co.uk
TDbf Access Violation
« on: June 27, 2008, 05:57:05 pm »
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.

WibblyTim

  • New Member
  • *
  • Posts: 46
    • http://www.wibblytim.co.uk
TDbf Access Violation
« Reply #1 on: July 01, 2008, 10:24:20 am »
It gets curiouser!

I have tested the code on my laptop which has the exact same version of Mandriva Linux and Lazarus (0.9.24) and the app compiled and ran without and errors at all.

I will look at the project settings in Lazarus on my main system and try again.

Tim. :roll:

andrea

  • Newbie
  • Posts: 4
Re: TDbf Access Violation
« Reply #2 on: July 04, 2008, 12:33:03 pm »
Quote from: "WibblyTim"
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;

WibblyTim

  • New Member
  • *
  • Posts: 46
    • http://www.wibblytim.co.uk
RE: Re: TDbf Access Violation
« Reply #3 on: July 08, 2008, 11:14:46 pm »
Thank you for your response. I used the Publish Project dialog to save the project and source files into a separate folder and loaded the project from there. Voila, no error!

I have no idea what I did wrong in the first place but it seems to be fine now.

Thanks anyway!   :)

 

TinyPortal © 2005-2018