J
JUMP1972
Unregistered / Unconfirmed
GUEST, unregistred user!
主程序中:
DM.SocketConn1.Connected:=false;
DM.SocketConn1.Connected:=true;
这样没有问题,而我在线程中连接,则提示“灾难性错误”,但此时已经连接上了数据库,
线程如下:
unit U_ThrdConnectDB;
interface
uses Classes, SConnect,SysUtils,ActiveX,MConnect,Dialogs;
type
TSocketConnectDBThread=class(TThread)
private
FSocketConn:TSocketConnection;
FDBConnected:Boolean;
protected
procedure Execute;override;
public
constructor Create(SocketConn:TSocketConnection);
property DBConnected:Boolean read FDBConnected;
destructor Destroy;override;
end;
implementation
{ TSocketConnectDBThread }
constructor TSocketConnectDBThread.Create(SocketConn: TSocketConnection);
begin
inherited Create(True);
FreeOnTerminate := True;
FSocketConn:=SocketConn;
Resume;
end;
destructor TSocketConnectDBThread.Destroy;
begin
inherited;
end;
end.
调用线程的代码:
try
if not DM.SocketConn1.Connected then
begin
MyThreadConnectDB:=TSocketConnectDBThread.Create(DM.SocketConn1);
while not MyThreadConnectDB.DBConnecteddo
Application.ProcessMessages;
if MyThreadConnectDB<>nil then
MyThreadConnectDB.Terminate;
if not DM.SocketConn1.Connected then
begin
lblRemoteServer.Caption:='断开';
MessageDlg('连接远程数据查询服务程序失败!无法完成数据查询工作.',mtError,[mbOk],0);
Exit;
end;
请大侠帮忙分析一下:
DM.SocketConn1.Connected:=false;
DM.SocketConn1.Connected:=true;
这样没有问题,而我在线程中连接,则提示“灾难性错误”,但此时已经连接上了数据库,
线程如下:
unit U_ThrdConnectDB;
interface
uses Classes, SConnect,SysUtils,ActiveX,MConnect,Dialogs;
type
TSocketConnectDBThread=class(TThread)
private
FSocketConn:TSocketConnection;
FDBConnected:Boolean;
protected
procedure Execute;override;
public
constructor Create(SocketConn:TSocketConnection);
property DBConnected:Boolean read FDBConnected;
destructor Destroy;override;
end;
implementation
{ TSocketConnectDBThread }
constructor TSocketConnectDBThread.Create(SocketConn: TSocketConnection);
begin
inherited Create(True);
FreeOnTerminate := True;
FSocketConn:=SocketConn;
Resume;
end;
destructor TSocketConnectDBThread.Destroy;
begin
inherited;
end;
end.
调用线程的代码:
try
if not DM.SocketConn1.Connected then
begin
MyThreadConnectDB:=TSocketConnectDBThread.Create(DM.SocketConn1);
while not MyThreadConnectDB.DBConnecteddo
Application.ProcessMessages;
if MyThreadConnectDB<>nil then
MyThreadConnectDB.Terminate;
if not DM.SocketConn1.Connected then
begin
lblRemoteServer.Caption:='断开';
MessageDlg('连接远程数据查询服务程序失败!无法完成数据查询工作.',mtError,[mbOk],0);
Exit;
end;
请大侠帮忙分析一下: