如下:收到的是8个byte类型 的数据,不知怎么显示在Memo上,高人指点一下。
procedure TFrmMain.MSCommComm(Sender: TObject);
var
vTmp:variant;
CodeSize:Integer;
i:integer;
begin
CodeSize:=0;
if MsComm.CommEvent=2 then // 收到数据的事件
begin
CodeSize:=MsComm.InBufferCount;
if CodeSize>0 then
begin
vTmp:=VarArrayCreate([0,CodeSize-1],varByte);
vTmp:=MsComm.Input;
//
end;
end;
end;
procedure TFrmMain.MSCommComm(Sender: TObject);
var
vTmp:variant;
CodeSize:Integer;
i:integer;
begin
CodeSize:=0;
if MsComm.CommEvent=2 then // 收到数据的事件
begin
CodeSize:=MsComm.InBufferCount;
if CodeSize>0 then
begin
vTmp:=VarArrayCreate([0,CodeSize-1],varByte);
vTmp:=MsComm.Input;
//
end;
end;
end;
解决方案 »
- 各位高手,请给我一个用ClientDataSet动态创建lookup字段的示例代码。
- 【变态】如何去掉ActiveX控件里面多余的(从基类继承下来的)属性?
- ★★【调查】成都软件行业的薪酬水平★★
- qReport如何插入空行的问题
- 又买了一条裤子,散分!前20个每人10分。
- 请问如何使用InstallShield Express - Borland Limited Edition
- 哪有好用的 Delphi 6 英文版下载?
- 偷懒之:棒个忙,找两组件
- 各位兄弟,帮忙啊,我捆在这里2天了,关于掉用保存好的ACCESS数据库问题。谢谢,急,马上给分,
- 关于Delphi6的一个小问题
- 关于用delphi开发大型游戏的讨论
- 在Delphi中如何调用由VB生成的Dll中的函数?
vTmp:variant;
ovTmp:olevariant;
CodeSize, i:Integer;
S :String;
begin
if Mscomm.Commevent = 2 then
begin
Sleep(20); //稍做等待!!
CodeSize:=MsComm.InBufferCount;
ovTmp := MsComm.Input;
vTmp:=VarArrayCreate([0,CodeSize-1],varByte);
vtmp := ovtmp;
S := '';
for i :=0 to CodeSize -1 do
S := S + IntToHex(vtmp[i]);
Memo1.lines.add(S);
end;
end;
s1:=buffer;
c:=s1[1];
ss:=ss+c;
i:=i+1;
lblDisplay.caption:=c+inttostr(i);
sendData[0]:=$02;
sendData[1]:=$03;
sendData[2]:=$00;
sendData[3]:=$00;
sendData[4]:=$00;
sendData[5]:=$01;
sendData[6]:=$84;
sendData[7]:=$39;
那就不对了。
发送正好与我上文写的接收相反,
vTmp:variant;
ovTmp:olevariant;
CodeSize, i:Integer;
begin
vTmp:=VarArrayCreate([0,8],varByte);
for i := 0 to 7 do
vTmp[i] := sendData[i];
ovTmp := vTmp;
MScomm.output := ovTmp ; //请注意! property Output: OleVariant ... TMscomm的输出类型是OleVariant !!!
end; 另外 楼主要显示的MEMO上 上述代码已经给你写清楚了,你的另外一篇帖子中提到十六进制转字符串 我已经给你详细的答复了。不知楼主明白没有...
for i :=0 to CodeSize -1 do
S := S + IntToHex(vtmp[i]);// 这句话总是报错,说是variant is not an array
我改这个样还是这句报错,
for i :=0 to CodeSize -1 do
vtmp[i]; // 这句话总是报错,说是variant is not an array
编译能通过,当收到数据后就报错。
----------------------------------------------------------------------------发送数据:
var
vTmp:variant;
begin
vTmp:=VarArrayCreate([0,7],varByte);
vTmp[0]:=$02;
vTmp[1]:=$03;
vTmp[2]:=$00;
vTmp[3]:=$00;
vTmp[4]:=$00;
vTmp[5]:=$01;
vTmp[6]:=$84;
vTmp[7]:=$39;
MsComm.Output:=vTmp;
end;
接收:
procedure TFrmMain.MSCommComm(Sender: TObject);
var
vTmp:variant;
ovTmp:olevariant;
CodeSize:Integer;
Code:Byte;
str:string;
i:integer;
begin
if MsComm.CommEvent=2 then
begin
sleep(20);
CodeSize:=MsComm.InBufferCount;
ovTmp := MsComm.Input;
vTmp:=VarArrayCreate([0,CodeSize-1],varByte);
vtmp := ovtmp;
str:='';
for i :=0 to CodeSize -1 do
str:=str + IntToHex(vtmp[i],2);
Memo1.lines.add(str);end;
showmessage(IntToStr(CodeSize));
end;实在不解!!!!
---> for i :=low(vtpm) to high(vtpm) do
感谢 大家的帮忙。
procedure TFrmMain.MSCommComm(Sender: TObject);
var
vTmp:variant;
ovTmp:olevariant;
CodeSize:Integer;
Code:Byte;
str:string;
i:integer;
begin
if MsComm.CommEvent=2 then
begin
sleep(20);
CodeSize:=MsComm.InBufferCount;
ovTmp := MsComm.Input;
vTmp:=VarArrayCreate([0,CodeSize-1],varByte);
vtmp := ovtmp;
str:='';
for i :=0 to CodeSize -1 do
begin
Code := vtmp[i];
str:=str + IntToHex(Code,2);
end;
Memo1.lines.add(str);end;
showmessage(IntToStr(CodeSize));
end;