我习惯于创建TThread后代来进行长时间的数据库操作.我通常的构造看起来像这样:
interface
type
TMyDBOp = class(TThread)
private
FConnection: TADOConnection;
FCommand1: TADOCommand;
FCommand2: TADOCommand; // and many more privated objects, vars ...
procedure InitDB;
procedure DoneDB;
procedure DoDBStuff; // and many more procedures and functions to structure the code
protected
procedure Execute; override;
public
constructor Create; reintroduce;
property X: T... // and many more properties to set on thread creation
end;
implementation
constructor TMyDBOp.Create;
begin
inherited Create(False);
end;
procedure TMyDBOp.InitDB;
begin
FConnection:= TADOConnection.Create(nil);
// setup all connection props, setup all other …Run Code Online (Sandbox Code Playgroud)