如何将这段VB代码转成delphi的 ( 积分: 100 )

  • 主题发起人 jiachenghuang
  • 开始时间
J

jiachenghuang

Unregistered / Unconfirmed
GUEST, unregistred user!
Private Sub Cmd_send_Click()
Dim temp(8) As Byte
Dim temp0$, temp1$, temp2$
Dim price, Digital As Integer
'发前四个字节
temp(0) = &HAA '指令头
temp(1) = &HF1 '设备地址
temp(2) = Val(Left(Txt_model.Text, 1)) '数据
temp(3) = Val(Mid(Txt_model.Text, 2, 1))
temp(4) = Val(Mid(Txt_model.Text, 3, 1))
temp(5) = Val(Mid(Txt_model.Text, 4, 1))
temp(6) = temp(2) + temp(3) + temp(4) + temp(5) '校验和
temp(7) = &HAB '指令尾

MSComm1.Output = temp

'发后四个字节
temp(0) = &HAA
temp(1) = &HF1
temp(2) = Val(Mid(Txt_model.Text, 5, 1))
temp(3) = Val(Mid(Txt_model.Text, 6, 1))
temp(4) = Val(Mid(Txt_model.Text, 7, 1))
temp(5) = Val(Mid(Txt_model.Text, 8, 1))
temp(6) = temp(2) + temp(3) + temp(4) + temp(5)
temp(7) = &HAB

MSComm1.Output = temp

End Sub
 
急啊,哪位帮一下,好了就撒分
 
没人能回答吗
 
很简单的
先定义一个数组变量
var
fdata:array[0..8] of byte
然后
fdata[0]:=&HAA;
fdata[1]:=&HF1;
....
....
comport1.Write(fdata[0],8);
这样就可以了,前提是你的delphi中要有comport这个控件,当然有mscomm也可以
 
&H是VB的转16进制的函数,delphi好象没有这个函数咯
 
你没有搞过delphi吗
在delphi中应是fdata[0]:=$AA;,上面只是个例子,你不能照抄的
我不可能全都给你写完,给你提示一下,你按思路作就行了
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
577
import
I
I
回复
0
查看
758
import
I
顶部