我先在全局里定义了一个mscomm:
comm:TMSComm;
然后用函数初始化并打开它:
if not Assigned(comm) then
comm:=TMSComm.Create(nil);
comm.CommPort:= 1;
comm.Settings:= '9600,n,8,1';
comm.PortOpen:= true;
comm.InputLen:=0;
comm.SThreshold := 1;
comm.NullDiscard:=false;然后我要定义一个函数,使得它成为comm的OnComm事件,该怎么定义实现?
comm:TMSComm;
然后用函数初始化并打开它:
if not Assigned(comm) then
comm:=TMSComm.Create(nil);
comm.CommPort:= 1;
comm.Settings:= '9600,n,8,1';
comm.PortOpen:= true;
comm.InputLen:=0;
comm.SThreshold := 1;
comm.NullDiscard:=false;然后我要定义一个函数,使得它成为comm的OnComm事件,该怎么定义实现?
MyFunction(MyFunction是自己定义的函数)我不知道怎么定义,老是报错啊
var
Mscomm1:TMSComm;
begin
Mscomm1:=TMSComm.Create();
Mscomm1.InBufferCount :=0; // 清空接收缓冲区
Mscomm1.InputLen :=0; // Input读取整个缓冲区内容
Mscomm1.RThreshold :=1; // 每次接收到字符即产生OnComm事件
MsComm1.OnComm:=ComGetData;
end;
procedure TForm1.ComGetData(Sender:TObject);
begin
if (sender is TMSComm) then
if (sender is TMSComm).CommEvent = 2 then
Memo1.text:=Memo1.Text+(sender is TMSComm).Input;
end;
光标处于.后面,报错:record,object or class type required.
var
Mscomm1:TMSComm;
begin
Mscomm1:=TMSComm.Create(nil);
Mscomm1.InBufferCount :=0; // 清空接收缓冲区
Mscomm1.InputLen :=0; // Input读取整个缓冲区内容
Mscomm1.RThreshold :=1; // 每次接收到字符即产生OnComm事件
MsComm1.OnComm:=ComGetData;
end;procedure TForm1.ComGetData(Sender:TObject);
begin
if (sender is TMSComm) then
if (Sender as TMSComm).CommEvent = 2 then
Memo1.text:=Memo1.Text+(sender as TMSComm).Input;
end;