如何在一个事件中正确调用同一线程多次? (50分)

X

xk

Unregistered / Unconfirmed
GUEST, unregistred user!
比如在Button1的Click事件中想启动一线程两次,此线程
为一Query,两次的Sql内容不同,我顺序调用TQueryThread.Create(...)
两次,出现Access Violation,请问如何正确调用线程?
 
谁能帮我?
 
var
Thread1,Thread2:TQueryThread;
begin
//here set options to make sure Thread1 and Thread2 are different
Thread1.Create(...);
Thread2.Create(...);
end;
 
将TQuery换为TBatchMove又如何?
 
hi,xk:
我认为利用俩个Thread不是好主意,不知你们是否知道Thread多了以后程序会
很慢。最好是写Thread的Execute时设置变量或写TButton的Tag.
详细的可以看Help或Email to me
 
在threads调用Query, 建议研究以下BDE和Delphi数据库控件原理。
TSession -> TDatabase -> TQuery(TTable)
每个thread需要独立的database connection.请按此为每个线程创建
query,否则只能出现访问错。如果还有数据库感应控件千万别忘了
GDI同步。可参见Sort和bkquery例子
 
我同意 hntangwei 的说法



 
i agree with HEPAM ,if you use two or more threads in database application, you must adopt Tsession to manage your Database connection and access.
 
接受答案了.
 
顶部