C
cchh
Unregistered / Unconfirmed
GUEST, unregistred user!
各位:
为何在 qryInThread.Open;的时候,
程序会没有规律的无响应???
有时候执行好好的,有时候整个程序就死了,
cpu 0%,没任何响应
调用函数
function ProcessDataThread( dataThread : TDataThread ):Boolean;
begin
Result := TRUE;
dataThread.Resume;
while not dataThread.Terminateddo
begin
Application.ProcessMessages;
Sleep(5);
end;
end;
function OpenSQLCompleteDataSetPlus( SQLQuery : TSQLCompleteDataSetPlus;
IsSelect : Boolean ):Boolean;
var
SQLThread : TSQLCompleteDataSetPlusThread;
i : Integer;
begin
if( IsSelect )then
begin
SQLQuery.Close;
SQLThread := TSQLCompleteDataSetPlusThread.Create(SQLQuery);
SQLThread.isSelect := IsSelect;
Result := ProcessDataThread(SQLThread);
SQLQuery.FieldDefs.Assign(SQLThread.qryInThread.FieldDefs);
SQLQuery.CreateDataSet;
SQLQuery.LogChanges := False;
while not SQLThread.qryInThread.Eofdo
begin
SQLQuery.Insert;
for i:= 0 to SQLThread.qryInThread.FieldDefs.Count-1do
SQLQuery.Fields.Fields.Value := SQLThread.qryInThread.Fields.Fields.Value;
SQLQuery.Post;
SQLThread.qryInThread.Next;
end;
SQLQuery.LogChanges := True;
SQLQuery.First;
FreeAndNil(SQLThread);
end
else
begin
SQLQuery.Close;
SQLThread := TSQLCompleteDataSetPlusThread.Create(SQLQuery);
SQLThread.isSelect := IsSelect;
Result := ProcessDataThread(SQLThread);
FreeAndNil(SQLThread);
end;
end;
线程定义
TDataThread = class( TThread )
qryInThread : TSQLQuery;
conInThread : TSQLConnection;
Log : TProcessLogger;
isSelect : Boolean;
constructor Create;
destructor Destory;
procedure WriteStartLog;
procedure WriteEndLog;
procedure WriteError;
end;
TSQLCompleteDataSetPlusThread = class( TDataThread )
public
constructor Create( SQLQuery : TSQLCompleteDataSetPlus );
procedure Execute;
override;
end;
{ TSQLThread }
constructor TDataThread.Create;
begin
inherited Create(TRUE);
FreeOnTerminate := FALSE;
qryInThread := TSQLQuery.Create(nil);
conInThread := TSQLConnection.Create(nil);
Log := TProcessLogger.Create;
conInThread.SQLHourGlass := False;
isSelect := True;
end;
destructor TDataThread.Destory;
begin
qryInThread.Close;
conInThread.Connected := False;
while( conInThread.ConnectionState <> csStateClosed )do
;
FreeAndNil(qryInThread);
FreeAndNil(conInThread);
FreeAndNil(Log);
end;
procedure TDataThread.WriteEndLog;
begin
Log.EndLog;
end;
procedure TDataThread.WriteStartLog;
var
TheMsg : String;
begin
case qryInThread.SQLConnection.ConnectionState of
csStateClosed:TheMsg := 'close';
csStateOpen:TheMsg := 'open';
csStateConnecting:TheMsg := 'connecting';
csStateExecuting:TheMsg := 'executing';
csStateFetching:TheMsg := 'fetching';
csStateDisconnecting:TheMsg := 'disconnecting';
end;
Log.StartLog(TheMsg);
end;
procedure TDataThread.WriteError;
begin
LogErrorMessage('Thread Error');
end;
constructor TSQLCompleteDataSetPlusThread.Create(SQLQuery: TSQLCompleteDataSetPlus);
var
Backup : TSQLConnection;
begin
inherited Create;
Backup := SQLQuery.SQLConnectionPlus;
conInThread.DriverName := Backup.DriverName;
AssignBASXConnection(conInThread,FALSE);
conInThread.LoginPrompt := False;
conInThread.Connected := True;
qryInThread.Close;
qryInThread.SQLConnection := conInThread;
qryInThread.SQL.Assign(SQLQuery.SQL);
qryInThread.Params.AssignValues(SQLQuery.Params);
end;
procedure TSQLCompleteDataSetPlusThread.Execute;
begin
Try
Synchronize(WriteStartLog);
if isSelect then
qryInThread.Open;
else
qryInThread.ExecSQL;
Synchronize(WriteEndLog);
Except
on e:exceptiondo
Synchronize(WriteError);
end;
Terminate;
end;
为何在 qryInThread.Open;的时候,
程序会没有规律的无响应???
有时候执行好好的,有时候整个程序就死了,
cpu 0%,没任何响应
调用函数
function ProcessDataThread( dataThread : TDataThread ):Boolean;
begin
Result := TRUE;
dataThread.Resume;
while not dataThread.Terminateddo
begin
Application.ProcessMessages;
Sleep(5);
end;
end;
function OpenSQLCompleteDataSetPlus( SQLQuery : TSQLCompleteDataSetPlus;
IsSelect : Boolean ):Boolean;
var
SQLThread : TSQLCompleteDataSetPlusThread;
i : Integer;
begin
if( IsSelect )then
begin
SQLQuery.Close;
SQLThread := TSQLCompleteDataSetPlusThread.Create(SQLQuery);
SQLThread.isSelect := IsSelect;
Result := ProcessDataThread(SQLThread);
SQLQuery.FieldDefs.Assign(SQLThread.qryInThread.FieldDefs);
SQLQuery.CreateDataSet;
SQLQuery.LogChanges := False;
while not SQLThread.qryInThread.Eofdo
begin
SQLQuery.Insert;
for i:= 0 to SQLThread.qryInThread.FieldDefs.Count-1do
SQLQuery.Fields.Fields.Value := SQLThread.qryInThread.Fields.Fields.Value;
SQLQuery.Post;
SQLThread.qryInThread.Next;
end;
SQLQuery.LogChanges := True;
SQLQuery.First;
FreeAndNil(SQLThread);
end
else
begin
SQLQuery.Close;
SQLThread := TSQLCompleteDataSetPlusThread.Create(SQLQuery);
SQLThread.isSelect := IsSelect;
Result := ProcessDataThread(SQLThread);
FreeAndNil(SQLThread);
end;
end;
线程定义
TDataThread = class( TThread )
qryInThread : TSQLQuery;
conInThread : TSQLConnection;
Log : TProcessLogger;
isSelect : Boolean;
constructor Create;
destructor Destory;
procedure WriteStartLog;
procedure WriteEndLog;
procedure WriteError;
end;
TSQLCompleteDataSetPlusThread = class( TDataThread )
public
constructor Create( SQLQuery : TSQLCompleteDataSetPlus );
procedure Execute;
override;
end;
{ TSQLThread }
constructor TDataThread.Create;
begin
inherited Create(TRUE);
FreeOnTerminate := FALSE;
qryInThread := TSQLQuery.Create(nil);
conInThread := TSQLConnection.Create(nil);
Log := TProcessLogger.Create;
conInThread.SQLHourGlass := False;
isSelect := True;
end;
destructor TDataThread.Destory;
begin
qryInThread.Close;
conInThread.Connected := False;
while( conInThread.ConnectionState <> csStateClosed )do
;
FreeAndNil(qryInThread);
FreeAndNil(conInThread);
FreeAndNil(Log);
end;
procedure TDataThread.WriteEndLog;
begin
Log.EndLog;
end;
procedure TDataThread.WriteStartLog;
var
TheMsg : String;
begin
case qryInThread.SQLConnection.ConnectionState of
csStateClosed:TheMsg := 'close';
csStateOpen:TheMsg := 'open';
csStateConnecting:TheMsg := 'connecting';
csStateExecuting:TheMsg := 'executing';
csStateFetching:TheMsg := 'fetching';
csStateDisconnecting:TheMsg := 'disconnecting';
end;
Log.StartLog(TheMsg);
end;
procedure TDataThread.WriteError;
begin
LogErrorMessage('Thread Error');
end;
constructor TSQLCompleteDataSetPlusThread.Create(SQLQuery: TSQLCompleteDataSetPlus);
var
Backup : TSQLConnection;
begin
inherited Create;
Backup := SQLQuery.SQLConnectionPlus;
conInThread.DriverName := Backup.DriverName;
AssignBASXConnection(conInThread,FALSE);
conInThread.LoginPrompt := False;
conInThread.Connected := True;
qryInThread.Close;
qryInThread.SQLConnection := conInThread;
qryInThread.SQL.Assign(SQLQuery.SQL);
qryInThread.Params.AssignValues(SQLQuery.Params);
end;
procedure TSQLCompleteDataSetPlusThread.Execute;
begin
Try
Synchronize(WriteStartLog);
if isSelect then
qryInThread.Open;
else
qryInThread.ExecSQL;
Synchronize(WriteEndLog);
Except
on e:exceptiondo
Synchronize(WriteError);
end;
Terminate;
end;