gpt4 book ai didi

delphi - 在执行 DBExpress 查询时,如何让我的程序响应用户输入?

转载 作者:行者123 更新时间:2023-12-03 15:50:58 26 4
gpt4 key购买 nike

ibdac 查询 ( http://www.devart.com/ibdac/components.html ) 有一个函数 executing 我可以在其中编写如下内容:

 while MyQuery.Executing do
begin
application.ProcessMessages;
Sleep(1);
end;

如何使用 dbexpress 查询实现相同的代码(没有类似的功能)?

最佳答案

没有类似的功能。但是您可以在后台线程中执行 MyQuery,主线程将在后台线程完成后等待。例如:

type
TMyThread = class(TThread)
private
FQuery: TSQLQuery;
protected
procedure Execute; override;
public
constructor Create(AQuery: TSQLQuery);
end;

constructor TMyThread.Create(AQuery: TSQLQuery);
begin
inherited Create;
FreeOnTerminate := False;
FQuery := AQuery;
end;

procedure TMyThread.Execute;
begin
FQuery.ExecSQL;
end;

var
oThread: TMyThread;
....

oThread := TMyThread.Create(MyQuery);
try
while not oThread.Finished do begin
Application.ProcessMessages;
Sleep(1);
end;
finally
oThread.Free;
end;

PS:顺便说一句,我正在使用AnyDAC 。它内置 background execution .

关于delphi - 在执行 DBExpress 查询时,如何让我的程序响应用户输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7468895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com