* * *

Author Topic: SQL Error  (Read 491 times)

greertr

  • Full Member
  • ***
  • Posts: 100
    • 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: 127
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: 100
    • Virtual Pilot Dashboard
Re: SQL Error
« Reply #2 on: January 11, 2017, 10:16:00 pm »
thx!

mangakissa

  • Hero Member
  • *****
  • Posts: 668
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 1.6 (32b) / FPC 3.0
Windows Vista /  10

greertr

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

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus