不会啊,打得开啊。
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ActiveX;type
Test = class(TThread)
private
{ Private declarations }
protected
ADODB: TADOConnection;
procedure Execute; override;
end; TForm2 = class(TForm)
ADOConnection1: TADOConnection;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
t: Test;implementation{$R *.dfm}{ Test }procedure Test.Execute;
begin
CoInitialize(nil);
ADODB := TADOConnection.Create(nil);
while not Terminated do
begin
Sleep(1000)
end;
ADODB.Free;
CoUninitialize;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
t := Test.Create(false);
end;procedure TForm2.FormDestroy(Sender: TObject);
begin
if Assigned(t) then
begin
t.Terminate;
t.WaitFor;
t.Free;
end;
end;end.
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ActiveX;type
Test = class(TThread)
private
{ Private declarations }
protected
ADODB: TADOConnection;
procedure Execute; override;
end; TForm2 = class(TForm)
ADOConnection1: TADOConnection;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
t: Test;implementation{$R *.dfm}{ Test }procedure Test.Execute;
begin
CoInitialize(nil);
ADODB := TADOConnection.Create(nil);
while not Terminated do
begin
Sleep(1000)
end;
ADODB.Free;
CoUninitialize;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
t := Test.Create(false);
end;procedure TForm2.FormDestroy(Sender: TObject);
begin
if Assigned(t) then
begin
t.Terminate;
t.WaitFor;
t.Free;
end;
end;end.
解决方案 »
- 请求汉化
- 难题:录入界面上,如何实现这种效果?
- 安装完sqlserver客户端后,如何用程序设置服务器别名?不用sqlserver的客户端实用工具
- 请问各位高手如何读写其它进程的内存?200分献上!!
- 用delphi能否实现电子地图的绘制?
- 急,寻找Rational Robot测试Delphi应用程序的组件
- 想要通过程序将DBChart1的title标题改下,如DBChart1.title.text:='各位大虾进来帮帮我!';这句为什么不能通过编译呢?
- 做IC卡管理系统的请留个QQ好吗?(26136463)
- 关于Timage和pagecontrol,求助!给分!
- 还有哪位在通宵
- 有没有熟悉Delphi的自由职业者
- Delphi版本的淘宝接口(TopAPI)开发
建议你把ADODB := TADOConnection.Create(nil);放在线程的Create事件中,ADODB.Free;放在Destroy事件中,CoInitialize(nil);和CoUninitialize;在每次操作数据时才调用CoInitialize(nil);
try
//操作数据库
finally
CoUninitialize;
end;
在线程 里面 频繁的 创建 销毁 链接
有必要吗
这个帖子里找到原因了,就是因为在ADOConnection创建的时候生成了IME的窗口,部分Office打开的时候使用Sendmessage向IME窗口发送消息,而线程中没有处理消息就会导致假死现象。
建议你把ADODB := TADOConnection.Create(nil);放在线程的Create事件中,ADODB.Free;放在Destroy事件中,CoInitialize(nil);和CoUninitialize;在每次操作数据时才调用CoInitialize(nil);
try
//操作数据库
finally
CoUninitialize;
end;按那帖子说的,这样应该就行了:
建议你把ADODB := TADOConnection.Create(nil);放在线程的Create事件中,ADODB.Free;放在Destroy事件中