例子看不太明白。
以下一个例程,可是这样对数据库又是如何分开操作。我要让每个线程执行不同的记录。
unit Unit2;
interface
uses
Classes,Db, DBTables,StdCtrls, SysUtils;
type
j = class(TThread)
private
query:Tquery;
protected
procedure Execute;
override;
end;
implementation
procedure j.Execute;
begin
freeonterminate:=true;
query:=Tquery.Create(nil);
query.DatabaseName:='delphi';
with querydo
begin
close;
sql.Clear ;
sql.add('select * from abc');
.....
open;
end;
if terminated then
exit;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
th:array[1..10] of TThread;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=1 to 10do
th:=j.Create(false);
end;
end.