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;

求关注!!!先谢谢各位了
...全文
144 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
shangwoo 2013-08-02
你的操作中有没有涉及到数据库,并且用了commit?
回复
相关推荐
发帖
Delphi
创建于2007-08-02

4925

社区成员

Delphi 开发及应用
申请成为版主
帖子事件
创建了帖子
2013-07-19 09:08
社区公告
暂无公告