* * *

Author Topic: TIP - Database new lookupfield with Zeos Access  (Read 745 times)

Eigil

  • New member
  • *
  • Posts: 5
TIP - Database new lookupfield with Zeos Access
« on: August 18, 2017, 08:24:16 pm »
I've been trying to create a lookupfield in a grid for hours, and it works in design mode but when I run the program, I always got the error
 "Can not perform opration on an inactive dataset".
 I have searched online and in the forum and can see that more people have the same problem. I have not been able to find a solution online.
 I then tried to do a test in Delphi6 just as in Lazarus here an error occurred when I defined new lookupfield in design mode with ZQueryXX set
 to active = true if active = false then ok.
  I then do the test in Lazarus by setting ZQueryXX to false before "RUN" and put in my case ZQuery1.active = true and ZTable1.active = true in the FormCreate method.
 Then the lookupfield in the grid was ok. :) (Lazarus 1.6.4 and 1.8RC4)
I hope this can be used by other in the forum.
Thank you for all the help that can be found here. :D

GAN

  • Jr. Member
  • **
  • Posts: 86
Re: TIP - Database new lookupfield with Zeos Access
« Reply #1 on: August 18, 2017, 09:58:20 pm »
I've had those kinds of mistakes in my early days with Zeos and I don't remember what my mistake was. Could you show the code or attach the project?
Lazarus 1.6 FPC 3.0.0 Linux Mint Mate 17.2 x86_64 GTK-2
Zeos 7.1.3 - Sqlite 3.8.2

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html

Eigil

  • New member
  • *
  • Posts: 5
Re: TIP - Database new lookupfield with Zeos Access
« Reply #2 on: August 19, 2017, 02:52:19 pm »
 Yes no problem.
J have made a small example for test in a zip-file.
J use MySql as database and have export the example data in af file named "test.sql"
There is also a Word file "info" with screen cuts. Hope you can use it.

GAN

  • Jr. Member
  • **
  • Posts: 86
Re: TIP - Database new lookupfield with Zeos Access
« Reply #3 on: August 21, 2017, 06:37:11 pm »
I think, because I can't test it (no have MySql), you only need to make de connection like this:

Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   ZConnection1.Connect;
  4.   ZQuery1.Active:=true;
  5.   ZQuery2.Active:=true;;
  6. end;    

BTW you also can use ZQuery1.Open instead ZQuery1.Active:=True (it's the same).
Lazarus 1.6 FPC 3.0.0 Linux Mint Mate 17.2 x86_64 GTK-2
Zeos 7.1.3 - Sqlite 3.8.2

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html

Eigil

  • New member
  • *
  • Posts: 5
Re: TIP - Database new lookupfield with Zeos Access
« Reply #4 on: August 22, 2017, 10:02:13 pm »
If it can help I have attach a example with sqlite-3.
Change the "LibraryLocation" in "ZConnection1" to the folder where you have the sqlite3.dll
for your machine WIN32 or WIN64.

GAN

  • Jr. Member
  • **
  • Posts: 86
Re: TIP - Database new lookupfield with Zeos Access
« Reply #5 on: August 23, 2017, 02:45:05 am »
See the attached file, it's working! On ZConnection1 write the full path to your db (or browse it).
The solution was close all connections in desing mode, then on the FormCreate event first open Zconnection1 , Zquery2,  Zquery1 in this order:

Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   if ZConnection1.Connected then ZConnection1.Disconnect;
  4.   ZQuery1.Close;
  5.   ZQuery2.Close;
  6.   ZConnection1.Connect;
  7.   ZQuery2.Open;
  8.   ZQuery1.Open;
  9. end;

Regards,
GAN.
Lazarus 1.6 FPC 3.0.0 Linux Mint Mate 17.2 x86_64 GTK-2
Zeos 7.1.3 - Sqlite 3.8.2

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html

 

Recent

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