看到个例子,建立一个ADOQUERY查询的线程
那主窗体怎么用这个线程,怎么调用,怎么销毁???
刚开始学,按例子做
先声明
var t:unit1; //UNIT1是主窗体
begin
t:=unit1.Create(adoquery1,'select * from TABLE');第一步var就提示错误了
E2029 '.' expected but ';' found主窗体只有一个ADOQUERY,一个按钮,一个DBGRID,一个DS请问要怎么调用???以下是线程的代码
unit Unit2;interfaceuses
Classes,ADODB,SysUtils,ActiveX;type
Unit1 = class(TThread)
constructor Create(ado:Tadoquery;s:string);//+
destructor Destroy;override; //+
private
a:Tadoquery;
ss:string;
{ Private declarations }
protected
procedure Execute; override;
end;implementationuses Unit1;{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure Unit1.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ Unit1 }constructor Unit1.Create(ado:Tadoquery;s:string); //+
begin
inherited create(true);
FreeOnTerminate:=true;
a:=ado;
ss:=s;
Resume;
end;procedure Unit1.Execute;
begin
{ Place thread code here }
CoInitialize(nil);//必须的
sleep(5000);
a.SQL.Add(ss);
try
a.Open;
except
raise
end;
end;destructor Unit1.Destroy; //+
begin
a:=nil;
inherited Destroy;
end;
end.
那主窗体怎么用这个线程,怎么调用,怎么销毁???
刚开始学,按例子做
先声明
var t:unit1; //UNIT1是主窗体
begin
t:=unit1.Create(adoquery1,'select * from TABLE');第一步var就提示错误了
E2029 '.' expected but ';' found主窗体只有一个ADOQUERY,一个按钮,一个DBGRID,一个DS请问要怎么调用???以下是线程的代码
unit Unit2;interfaceuses
Classes,ADODB,SysUtils,ActiveX;type
Unit1 = class(TThread)
constructor Create(ado:Tadoquery;s:string);//+
destructor Destroy;override; //+
private
a:Tadoquery;
ss:string;
{ Private declarations }
protected
procedure Execute; override;
end;implementationuses Unit1;{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure Unit1.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ Unit1 }constructor Unit1.Create(ado:Tadoquery;s:string); //+
begin
inherited create(true);
FreeOnTerminate:=true;
a:=ado;
ss:=s;
Resume;
end;procedure Unit1.Execute;
begin
{ Place thread code here }
CoInitialize(nil);//必须的
sleep(5000);
a.SQL.Add(ss);
try
a.Open;
except
raise
end;
end;destructor Unit1.Destroy; //+
begin
a:=nil;
inherited Destroy;
end;
end.
解决方案 »
- 新添加数据 求助往数据库中
- 如何导入有密码的EXCEL文件
- 利用递归删除文件夹,如果文件过多的话,会出现假死。
- 中邪了??帮看一个delphi 填Excel问题!
- [求助]有关ReportBulider控件的问题!
- 几个问题大家来看看啊~~~~~~~~简单的难一点的都有~~~~~~~
- 如何删除ini中的某一项,例子如下.
- access数据库的局域网连接 (与操作系统有关)
- 怎么往数据库中导入多个文件和导出多个文件到硬盘上?UP有风
- 请问有没有类似网页分析的软件(htm分析)?
- delphi备份与恢复的问题?请大家帮我看下代码
- 英文版windows 7下的Delphi7,在pas單元不能写中文注释???
这句是说应该用.号而你用了;号.
这个怎么也用unit1呢,unit1不是主窗体吗,不能重复
是主窗体里声明线程哪里报错
var t:unit1;这里就提示错了,而且是提示 E2029 '.' expected but ';' found 这个所以很奇怪
begin
inherited create(true);CoInitialize(nil);//必须的 ,注意释放哦,好习惯。 FreeOnTerminate:=true;
a:=ado;
ss:=s;
Resume;
end;procedure Unit1.Execute;
begin
{ Place thread code here }
//CoInitialize(nil);//必须的
sleep(5000);
a.SQL.Add(ss);
try
a.Open;
except
raise //不能这样,这里的异常不能举起,可以考虑WriteLog
end;
end;
我是想问主窗体怎么运行这个线程
声明的时候就报错了
“var t:unit1; //UNIT1是主窗体”
还是好好看书吧。
unit1不是主窗体了
就是不懂才问啊!!