Lazarus

Programming => General => Topic started by: greertr on January 11, 2017, 02:48:02 pm

Title: SQL Error
Post by: greertr 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?
Title: Re: SQL Error
Post by: patyi 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;
Title: Re: SQL Error
Post by: greertr on January 11, 2017, 10:16:00 pm
thx!
Title: Re: SQL Error
Post by: mangakissa 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.
Title: Re: SQL Error
Post by: greertr on January 12, 2017, 10:33:30 am
thx!
TinyPortal © 2005-2018