如果ADOConnection不是在主线程创建,那么在vmware虚拟机中执行程序,切换输入法会导致用户界面无响应。测试线程的代码如下:
type
TDataAccessThread = class(TThread)
private
FConnection: TADOConnection;
protected
procedure Execute; override;
end;
procedure TDataAccessThread.Execute;
begin
inherited;
CoInitialize(nil);
FConnection := TADOConnection.Create(nil);
try
while not Self.Terminated do
Sleep(1000);
finally
FConnection.Free;
CoUninitialize;
end;
end;
新建一个Form Application,放置一个TEdit上去,然后在FormCreate事件(当然也可以在其它时机)创建上面的线程。线程创建后,尝试切换到中文输入法在Edit中输入汉字,程序会无响应。很坑爹是吧?
解决办法是,在主线程创建ADOConnection。线程代码改为如下:
type
TDataAccessThread = class(TThread)
private
FConnection: TADOConnection;
protected
proce