delphi多线程出现错误:“无法在此会话中启动更多事务”

ctjtn 2013-07-19 09:08:32
如题,线程定义如下:

unit Thread_Read;

interface

uses
Classes ,SPComm,Forms,MP_P_BaseForm,MP_P_DMMain,Controls,SysUtils,Buttons,ComCtrls;

type
Thread_Rd = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
Spcomm_RW:TComm;
constructor Create(str_ComName1: string; spcomm_RW1: TComm);
procedure GetOutString;
procedure ExcuteGetOutStr();
procedure FreeControlByIndex();
procedure ExcuteFreeControlByIndex();
procedure SetInputString();
procedure ExcuteSetInputStr();
procedure ExcuteCOM1;
procedure ExcuteCOM3;
end;

implementation
{ Thread_Read }
uses
MP_62056_RW;

constructor Thread_Rd.Create(str_ComName1: string; spcomm_RW1: TComm);
begin
Str_ComName:=str_ComName1;
Spcomm_RW:= spcomm_RW1;
inherited Create(False);
end;

procedure Thread_Rd.Execute;
{ Place thread code here }
begin
if Str_ComName='COM1' then
Frm_62056_RW.ReadOperateCOM1 //为主窗口的过程
else if Str_ComName='COM2' then
Frm_62056_RW.ReadOperateCOM2
else if Str_ComName='COM3' then
Frm_62056_RW.ReadOperateCOM3
end;

在主线程开启线程:
procedure TFrm_62056_RW.bbtn_ReadClick(Sender: TObject);
begin
Thread_ReadCOM1:= Thread_Rd.Create('COM1',spcomm_RW1);
Thread_ReadCOM2:= Thread_Rd.Create('COM2',spcomm_RW2);
end;
procedure TFrm_62056_RW.ReadOperateCOM1;
var
Str_Error:string;
begin
try
if ReadDataProcess(Gl_Str_MTypeNo,Gl_Str_MeterNo,'COM1',Str_Error,Memo_Debug1,spcomm_RW)<0 then//此处出现如题错误
begin
ShowWarningWithMsg(Str_Error);
end else
begin
ShowInformation(sb_Object.Panels[con_PnlNo_ObjectCount].Text+','+
sb_Object.Panels[con_PnlNo_SucceedCount].Text+','+
sb_Object.Panels[con_PnlNo_FailedCount].Text);
end;
finally
if bbtn_Read.CanFocus then bbtn_Read.SetFocus;
end;
end;

procedure TFrm_62056_RW.ReadOperateCOM2;
var
Str_Error:string;
begin
try
if ReadDataProcess(Gl_Str_MTypeNo,Gl_Str_MeterNo,'COM2',Str_Error,memo_Debug2,spcomm_RW2)<0 then
begin
ShowWarningWithMsg(Str_Error);
end else
begin
ShowInformation(sb_Object.Panels[con_PnlNo_ObjectCount].Text+','+
sb_Object.Panels[con_PnlNo_SucceedCount].Text+','+
sb_Object.Panels[con_PnlNo_FailedCount].Text);
end;
finally
Class_GVar.Str_ExecLockSys:=con_ExecLockSys_Yes;
if bbtn_Read.CanFocus then bbtn_Read.SetFocus;
end;
end;

求关注!!!先谢谢各位了
...全文
240 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
shangwoo 2013-08-02
  • 打赏
  • 举报
回复
你的操作中有没有涉及到数据库,并且用了commit?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧