C
cqwty
Unregistered / Unconfirmed
GUEST, unregistred user!
我在线程单元里面写了代码,将mscomm1.input加入到memo中,可是不行,
非要在oncomm事件中写,线程单元的代码如下:
unit mycommthread;
interface
uses
Classes,MSCommLib_TLB,shellapi,sysutils,StdCtrls,comctrls;
type
mycomm = class(TThread)
private
{ Private declarations }
amscomm:tmscomm;
amemo:tmemo;
astring:string;
protected
procedure Execute;
override;
procedure disinfo;
public
constructor create(mscomm:tmscomm;memo:tmemo);
end;
implementation
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure mycomm.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ mycomm }
constructor mycomm.create(mscomm:tmscomm;memo:tmemo);
begin
inherited create(false);
amscomm:=mscomm;
amemo:=memo;
freeonterminate:=true;
end;
procedure mycomm.Execute;
begin
if amscomm.CommEvent=2 then
astring:=amscomm.Input;
synchronize(disinfo);
end;
procedure mycomm.disinfo;
begin
amemo.lines.add(astring);
end;
end.
哪位大侠救救命吧!还有一个问题就是:
当创建线程的时候,一定要mscomm1.openport:=true;
否则提示说端口没有打开!
非要在oncomm事件中写,线程单元的代码如下:
unit mycommthread;
interface
uses
Classes,MSCommLib_TLB,shellapi,sysutils,StdCtrls,comctrls;
type
mycomm = class(TThread)
private
{ Private declarations }
amscomm:tmscomm;
amemo:tmemo;
astring:string;
protected
procedure Execute;
override;
procedure disinfo;
public
constructor create(mscomm:tmscomm;memo:tmemo);
end;
implementation
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure mycomm.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ mycomm }
constructor mycomm.create(mscomm:tmscomm;memo:tmemo);
begin
inherited create(false);
amscomm:=mscomm;
amemo:=memo;
freeonterminate:=true;
end;
procedure mycomm.Execute;
begin
if amscomm.CommEvent=2 then
astring:=amscomm.Input;
synchronize(disinfo);
end;
procedure mycomm.disinfo;
begin
amemo.lines.add(astring);
end;
end.
哪位大侠救救命吧!还有一个问题就是:
当创建线程的时候,一定要mscomm1.openport:=true;
否则提示说端口没有打开!