定义不定义动态数组没关系,因为你使用的时候,如果系统发现没有分配内存空间,系统将自动完成.
首先触发此事件,肯定是有数据过来了.否则不会产生.
给你个例子你可参考一下.
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
Com.CommPort:=1;
Com.Settings:='4800,N,8,1';
Com.RThreshold:=1;
Com.InputMode:=comInputModeBinary;
Com.InputLen := 0;
Com.SThreshold := 0; //一次发送所有数据
Com.InBufferCount := 0; //清空读取缓冲区
Com.OutBufferCount := 0; //清空发送缓冲区
Com.PortOpen:=True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
senddata:array[1..5] of char;
sendstr:string;
i:longint;
begin
senddata[1]:=chr($0E); //要发送的数据
senddata[2]:=chr($03);
senddata[3]:=chr($FF);
senddata[4]:=chr($03);
senddata[5]:=chr($00);
sendstr:='';
for i:=1 to 5 do
sendstr:=sendstr + senddata;
com.output:=sendstr; //发送数据
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
senddata:array[1..5] of char;
sendstr:string;
i:longint;
begin
senddata[1]:=chr($0E); //要发送的数据
senddata[2]:=chr($03);
senddata[3]:=chr($FF);
senddata[4]:=chr($03);
senddata[5]:=chr($00);
sendstr:='';
for i:=1 to 5 do
sendstr:=sendstr + senddata;
com.output:=sendstr; //发送数据
end;
procedure TForm1.ComComm(Sender: TObject);
var
reData:array of Variant;
Restr:string;
i:longint;
begin
case com.CommEvent of
comEvReceive:
begin
redata:=com.Input;
Restr:='';
for i:=0 to vararrayhighbound(redata,1) do
Restr:=Restr + inttohex(redata,2)+' ';
end;
end;
end;
end.