红
红金
Unregistered / Unconfirmed
GUEST, unregistred user!
我做了个简单的例子。
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.text:='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.
调用时创建一个线程可以,动态创建10个时出错??
不知为什么??请各位大侠帮忙!!!
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.text:='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.
调用时创建一个线程可以,动态创建10个时出错??
不知为什么??请各位大侠帮忙!!!