Recent

Author Topic: SQL Error  (Read 2453 times)

greertr

  • Full Member
  • ***
  • Posts: 113
    • Virtual Pilot Dashboard
SQL Error
« on: January 11, 2017, 02:48:02 pm »
I went in to do an edit n my Lz program, and didn't do anything to any SQL stuff, and now, when I compile I get an error about the SQL Library called out of sequence.  This error has been occurring randomly, then goes away, also randomly.

Here is a copy of my code that seems to be causing the problem...
Code: Pascal  [Select][+][-]
  1. procedure TForm12.FormCreate(Sender: TObject);
  2. begin
  3.   Label1.caption := 'Number of Records:  ' + inttostr(ZQuery1.RecordCount-1);
  4.   Label2.caption := 'Number of Selected Record:  ' + inttostr(ZQuery1.RecNo);
  5. end;

Anyone know what I need to do to correct this?
« Last Edit: January 11, 2017, 03:06:54 pm by greertr »

patyi

  • Full Member
  • ***
  • Posts: 168
Re: SQL Error
« Reply #1 on: January 11, 2017, 06:36:19 pm »
    procedure TForm12.FormCreate(Sender: TObject);
    begin
      if ZQuery1.Active then begin
         Label1.caption := 'Number of Records:  ' + inttostr(ZQuery1.RecordCount-1);
         Label2.caption := 'Number of Selected Record:  ' + inttostr(ZQuery1.RecNo);
      end;
    end;

greertr

  • Full Member
  • ***
  • Posts: 113
    • Virtual Pilot Dashboard
Re: SQL Error
« Reply #2 on: January 11, 2017, 10:16:00 pm »
thx!

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: SQL Error
« Reply #3 on: January 12, 2017, 09:19:53 am »
Why using 'ZQuery1.RecordCount-1'?
Recordcount gives the actual count of records.

Don't put it in formcreate. It only shows once, but you want to see the selected recordnumber everytime you change the record. Create a procedure like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm12.Selectednowithrowcount;
  2. begin
  3.    Label1.caption := format('Number of Selected Record: %d/%d ',[ZQuery1.RecNo,Zquery1.Recordcount]);
  4. end;
  5.  
Call this procedure in de Afterscroll event of your dataset.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

greertr

  • Full Member
  • ***
  • Posts: 113
    • Virtual Pilot Dashboard
Re: SQL Error
« Reply #4 on: January 12, 2017, 10:33:30 am »
thx!

 

TinyPortal © 2005-2018