-------------- snip -------------
type SQLQueryThread=class(TThread)
private
sqlstr:ansistring;
public
constructor Create(querystr:ansistring);
procedure Execute;
override;
destructor Destroy;
override;
end;
var sema_threads_running,sema_threads_completed:integer;
constructor SQLQueryThread.Create(querystr:ansistring);
begin
inherited Create(false);
sqlstr:=querystr;
inc(sema_threads_running);
end;
procedure SQLQueryThread.Execute;
var dbcmd:TMyCommand;
begin
dbcmd:=TMyCommand.Create(frm_search_database);
dbcmd.CommandTimeout:=3000;
dbcmd.ParamCheck:=false;
dbcmd.Prepared:=false;
dbcmd.Connection:=frm_main.MyConnection1;
dbcmd.SQL.Add(sqlstr);
dbcmd.Execute;
dbcmd.Free;
end;
destructor SQLQueryThread.Destroy;
begin
dec(sema_threads_running);
inc(sema_threads_completed);
inherited Destroy;
end;
//this part uses the threads
progressbar1.Maximum:=sqlcommandlist.Count-1;
sema_threads_running:=0;
sema_threads_completed:=0;
for i:=0
to sqlcommandlist.Count-1
do
begin
//alle befehle uebertragen
SQLQueryThread.Create(sqlcommandlist.Strings[i]);
repeat
application.ProcessMessages;
sleep(1);
until(sema_threads_running<maxquerythreads);
progressbar1.Position:=sema_threads_completed;
end;
repeat
application.ProcessMessages;
sleep(1);
progressbar1.Position:=sema_threads_completed;
until(sema_threads_running=0);