TDbf Access Violation lazarus / 16-Databases ---------------------------------------------------------------------- WibblyTim · 2008-06-27 15:57 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 · 2008-07-01 08:24 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 · 2008-07-04 10:33 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 · 2008-07-08 21:14 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!