部分代码:<br> TRunExeSQLStrList = Class(TThread)<br> Private<br> Protected<br> Procedure Execute; Override;<br> Procedure RunExeSQL;<br> Public<br> Constructor Create;<br> End;<br>{<br>****************************** TRunExeSQLStrList *******************************<br>}<br><br>Constructor TRunExeSQLStrList.Create;<br>Begin<br> RunSQL := False; //全局 信号量,为False是禁止创建该线程<br> Inherited Create(False); //创建即执行<br> FreeOnTerminate := True; //执行完即销毁<br>End;<br><br>Procedure TRunExeSQLStrList.Execute;<br>Begin<br> If Not Terminated Then<br> RunExeSQL;<br>End;<br><br>Procedure TRunExeSQLStrList.RunExeSQL;<br>Begin //SQLStrListA、SQLStrListB 为全局变量 交换存储要执行的SQL语句 <br> If LockSQL Then //SQLStrListA 为活动的<br> Begin<br> Try<br> LockSQL := False; //切换 SQLStrListB 为活动的 以便执行 SQLStrListA 中SQL语句<br> If SQLStrListA.Count > 0 Then<br> ExeListSQL(@SQLStrListA); //*********执行此处出错<br>//ExeListSQL 为我的动态链接库引出过程 代码附在后面<br> Finally<br> SQLStrListA.Clear;<br> End;<br> End;<br><br> If Not LockSQL Then //SQLStrListB 为活动的<br> Begin<br> Try<br> LockSQL := True; //切换 SQLStrListA 为活动的 以便执行 SQLStrListB 中SQL语句<br> If SQLStrListB.Count > 0 Then<br> ExeListSQL(@SQLStrListB);<br> Finally<br> SQLStrListB.Clear;<br> Sleep(5000);<br> RunSQL := True; //线程TRunExeSQLStrList创建触发信号<br> End;<br> End;<br>End;<br><br><br>Function ExeListSQL(ASQL: PTStr): Boolean; StdCall; External 'DataControl.DLL';<br>//PTStr = ^TStrings;<br>//ExeListSQL不附在线程中执行是正常的,函数代码如下:<br>Function TDM.ProtExeSQL(ASQL: PTStr): Boolean;<br>Var<br> I, J: Integer;<br> Str: String;<br>Begin<br> Result := True;<br> J := ASQL^.Count;<br> If J = 0 Then<br> Exit;<br> If stClosed In DM.ADOCon.State Then<br> DM.ADOCon.Open;<br> DM.ADOQ.Close;<br> DM.ADOCon.BeginTrans;<br> Try <br> J := ASQL^.Count;<br> DM.ADOQ.SQL.Clear;<br> For I := 0 To J - 1 Do<br> Begin<br> If I < 10 Then<br> Str := #13 + ASQL^;<br> DM.ADOQ.SQL.Add(ASQL^);<br> If DM.ADOQ.SQL.Count > 100 Then<br> Begin<br> DM.ADOQ.ExecSQL;<br> DM.ADOQ.SQL.Clear;<br> End;<br> End;<br> If DM.ADOQ.SQL.Count > 0 Then<br> DM.ADOQ.ExecSQL;<br> DM.ADOCon.CommitTrans;<br> Except<br> DM.ADOCon.RollbackTrans;<br> MessageBox(0, PChar('&Ecirc;&yacute;&frac34;&Yacute;&iquest;&acirc;&sup2;&Ugrave;×÷&Ouml;&acute;&ETH;&ETH;&sup3;&ouml;&acute;í!' + Str), '&Ecirc;&yacute;&frac34;&Yacute;&iquest;&acirc;&sup2;&Ugrave;×÷', MB_ICONERROR);<br> Result := False;<br> End;<br><br> DM.ADOQ.Close;<br>End;