Recent

Author Topic: Async ZQuery.Open  (Read 2775 times)

DarkCall

  • Newbie
  • Posts: 3
Async ZQuery.Open
« on: October 28, 2021, 08:48:03 pm »
My application is totally interrupted when I do ZQuery.Open;
Is there a way to make it an Asynchronous command?

loaded

  • Sr. Member
  • ****
  • Posts: 374
Re: Async ZQuery.Open
« Reply #1 on: October 29, 2021, 08:30:07 am »
You can try using thread.
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

DarkCall

  • Newbie
  • Posts: 3
Re: Async ZQuery.Open
« Reply #2 on: October 29, 2021, 08:40:52 pm »
How to start?

Code: Pascal  [Select][+][-]
  1. procedure TForm2.DBComboLookupClick(Sender: TObject);
  2. begin
  3.    FCounter := FCounter+1;
  4.    Application.QueueAsyncCall(@Async,FCounter);
  5. end;
  6.  
  7. procedure TForm2.Async(Data: PtrInt);
  8. begin
  9.   ZConnection1.ZQuery1.Open;
  10. end;

It's still pause my application until ZQuery opened.

[Edited to add code tags; please read How to use the Forum.]
« Last Edit: October 30, 2021, 01:59:29 am by trev »

loaded

  • Sr. Member
  • ****
  • Posts: 374
Re: Async ZQuery.Open
« Reply #3 on: October 30, 2021, 05:44:26 am »
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, DB, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
  9.   DBGrids, ZConnection, ZDataset;
  10. type
  11.   { TH_for_zqoon }
  12.   TH_for_zqoon = class(TThread)
  13.   private
  14.     procedure Opened;
  15.   protected
  16.     procedure Execute; override;
  17.   end;
  18.  
  19.   { TForm1 }
  20.   TForm1 = class(TForm)
  21.     Button_database_opener: TButton;
  22.     ZConnection1: TZConnection;
  23.     ZQuery1: TZQuery;
  24.     procedure Button_database_openerClick(Sender: TObject);
  25.   private
  26.  
  27.   public
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33. implementation
  34. {$R *.lfm}
  35. { For Thread }
  36. procedure TH_for_zqoon.Opened;
  37. begin
  38.  Showmessage('Zquery Opened');
  39. end;
  40.  
  41. procedure TH_for_zqoon.Execute;
  42. begin
  43.  Form1.ZQuery1.Open;
  44.  Synchronize(@Opened);
  45. end;
  46.  
  47. { TForm1 }
  48. procedure TForm1.Button_database_openerClick(Sender: TObject);
  49. var
  50.   Zopener : TH_for_zqoon;
  51. begin
  52.   Zopener:=TH_for_zqoon.Create(false);
  53. end;
  54. end.
  55.  
  56.  
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

mangakissa

  • Hero Member
  • *****
  • Posts: 1126
Re: Async ZQuery.Open
« Reply #4 on: November 01, 2021, 04:32:44 pm »
My application is totally interrupted when I do ZQuery.Open;
Is there a way to make it an Asynchronous command?
Is this always when you open queries or only for this particulair?
You're not giving much information about the query.

I'm not a fan of using queries in threads if you nothing more than just open it.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

 

TinyPortal © 2005-2018