Basic Example of Threaded SDAC with Grid and BreakExec

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
coder6910
Posts: 3
Joined: Mon 26 Oct 2015 03:32

Basic Example of Threaded SDAC with Grid and BreakExec

Post by coder6910 » Mon 25 May 2020 16:17

Please provide an example of SDAC using a threaded query that populates a grid and can be cancelled with a breakexec. The threaded example in demos has a stop button - but does not use a breakexec pattern. Also, your help document doesn't have enough detail on how to do this.

Regards,
Pat

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Basic Example of Threaded SDAC with Grid and BreakExec

Post by Stellar » Mon 01 Jun 2020 08:52

You can run the query in a separate thread and, if necessary, terminate execution of the query in the main thread of the application.
For example:

Code: Select all

type
  TExecThread = class(TThread)
  private
    FQuery: TMSQuery;
  public
    constructor Create(const Query: TMSQuery);
    destructor Destroy(); override;

    procedure Execute; override;
  end;

implementation

{$R *.dfm}

{ TExecThread }

constructor TExecThread.Create(const Query: TMSQuery);
begin
  inherited Create(True);

  FQuery := Query;
end;

destructor TExecThread.Destroy;
begin
  FQuery := nil;

  inherited;
end;

procedure TExecThread.Execute;
begin
  inherited;

  FQuery.Open;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  Thread: TExecThread;
begin
  MSConnection1.Connect;
  MSQuery1.SQL.Text := 'SELECT * FROM Table_Name';

  Thread := TExecThread.Create(MSQuery1);
  Thread.FreeOnTerminate := True;
  Thread.Start;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  MSQuery1.BreakExec;
end;

Post Reply