Recent

Author Topic: Lazarus and Access-Database  (Read 2543 times)

schand99

  • Newbie
  • Posts: 4
Lazarus and Access-Database
« on: November 19, 2020, 01:52:06 pm »
Hi,

I have encountered a strange behaviour on Lazarus and MS Access database:
I open a SQL Query which selects a number of records. On the open records I have to check each record for the content of a field. I do this within a repeat ... until loop:

A error raises up when rSSQL.Next points to the last record into rSSQL, just befor rSSQL.EOF is true
Code: Pascal  [Select][+][-]
  1. ...
  2. rSSQL.open;
  3. if not rSSQL.EOF do begin
  4.    rSSQL.First;
  5.    repeat
  6.         ... do something
  7.        rSSQL.Next;
  8.    until rSSQL.EOF;
  9. end;
  10.  

If in the same code I first point to the last records and after that I point to the first record, there is no error
Is there anybody else having this problem? Or maybe someone who can explain this strange behavior?
Code: Pascal  [Select][+][-]
  1. ...
  2. rSSQL.open;
  3. if not rSSQL.EOF do begin
  4.    rSSQL.Last;           //  <- this one
  5.    rSSQL.First;
  6.    repeat
  7.         ... do something
  8.        rSSQL.Next;
  9.    until rSSQL.EOF;
  10. end;
  11.  


Zvoni

  • Hero Member
  • *****
  • Posts: 2330
Re: Lazarus and Access-Database
« Reply #1 on: November 20, 2020, 09:26:40 am »
I remember having similiar issues with DAO/ADO on VB6, that i had to move to the last record, and then back to the first, because the EOF and/or recordcount wasn't set properly or something like that.
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Lazarus and Access-Database
« Reply #2 on: November 20, 2020, 10:59:06 am »
The attached demo does the same: it iterates through an Access-based dataset and counts the empty fields, and the error does not occur.

What is different to your case? I could imagine that the fact that the query is attached to a DBGrid in my demo could cause .Last already being called. So, please give more details, or better: upload a simple compilable demo (only pas, lfm, lpi, lpr and database files, all in a common zip, like I did).

Zvoni

  • Hero Member
  • *****
  • Posts: 2330
Re: Lazarus and Access-Database
« Reply #3 on: November 20, 2020, 11:05:21 am »
Found something:
http://allenbrowne.com/ser-29.html
Look at Point 5. Sounds like your Problem
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018