H
halei
Unregistered / Unconfirmed
GUEST, unregistred user!
我刚开始学习使用线程,我看着例子写了以下代码,但是运行后,一按botton1,
就弹出"thread error:句柄无效 (6)"
请帮帮忙
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ADOQuery1: TADOQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
tMyThread.Create(adoquery1);
end;
end.
unit Unit2;
//线程单元
interface
uses
Classes,ADODB;
type
TMyThread=class(TThread)
private
qry:tadoquery;
protected
procedure execute;override;
public
constructor create(querya:tadoquery);overload;
end;
implementation
uses Unit1;
constructor
TMyThread.Create(querya:tadoquery);
begin
qry:=querya;
FreeOnTerminate:=True;
end;
procedure tmythread.Execute;
begin
qry.open;
end;
end.
就弹出"thread error:句柄无效 (6)"
请帮帮忙
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ADOQuery1: TADOQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
tMyThread.Create(adoquery1);
end;
end.
unit Unit2;
//线程单元
interface
uses
Classes,ADODB;
type
TMyThread=class(TThread)
private
qry:tadoquery;
protected
procedure execute;override;
public
constructor create(querya:tadoquery);overload;
end;
implementation
uses Unit1;
constructor
TMyThread.Create(querya:tadoquery);
begin
qry:=querya;
FreeOnTerminate:=True;
end;
procedure tmythread.Execute;
begin
qry.open;
end;
end.