#和$后面跟的数值要怎么才能够转换(100分)

  • 主题发起人 大白菜
  • 开始时间

大白菜

Unregistered / Unconfirmed
GUEST, unregistred user!
我在程序中要用到
m_EtherAddrDis.AddrByte[0]:=$52;
m_EtherAddrDis.AddrByte[1]:=$54;
m_EtherAddrDis.AddrByte[2]:=$ab;
m_EtherAddrDis.AddrByte[3]:=$26;
m_EtherAddrDis.AddrByte[4]:=$1f;
m_EtherAddrDis.AddrByte[5]:=$b3;
m_IPAddrSou.AddrByte[0]:=#192;
m_IPAddrSou.AddrByte[1]:=#168;
m_IPAddrSou.AddrByte[2]:=#0;
m_IPAddrSou.AddrByte[3]:=#5;
m_IPAddrDis.AddrByte[0]:=#192;
m_IPAddrDis.AddrByte[1]:=#168;
m_IPAddrDis.AddrByte[2]:=#0;
m_IPAddrDis.AddrByte[3]:=#200;
分别代表网卡MAC地址和IP地址,上面
的例子里面是定的,现在我要他们能够通
过EDIT框输进去。应该用什么方法定义变量和付值。
它们的分别定义如下。
PEtherAddr=^EtherAddr;
EtherAddr=record
AddrByte:array [0..5] of byte;
end;

PIPAddr=^IPAddr;
IPAddr=record
AddrByte:array [0..3] of char;
end;
 
混/
直接就可以了
 

假设 Edit1.Text 为 '$26'
则 m_IPAddrDis.AddrByte[2]:= Byte( IntToStr( Edit1.Text ) );
若 Edit1.Text 为 '#200',则
先把#去掉,再转为 Integer;
 
第一个问题我已经弄清楚了,是可以用
m_EtherAddrSou.AddrByte[0]:=byte(strtoint('$'+SouMac[0]));
m_EtherAddrSou.AddrByte[1]:=byte(strtoint('$'+SouMac[1]));
m_EtherAddrSou.AddrByte[2]:=byte(strtoint('$'+SouMac[2]));
m_EtherAddrSou.AddrByte[3]:=byte(strtoint('$'+SouMac[3]));
m_EtherAddrSou.AddrByte[4]:=byte(strtoint('$'+SouMac[4]));
m_EtherAddrSou.AddrByte[5]:=byte(strtoint('$'+SouMac[5]));
注意要'$'

to musicwind
我说的并非是Edit1.Text 为‘#200’,而是为'200',
但我要在付值的时候让m_IPAddrDis.AddrByte[3] 为 '#200'
其中‘#200’部分应该是一个变量,能够通过Edit1.Text 更改。
 

注意:
#200表示什么?表示一个值为Asic码为200的Char,并且#后面的数值不能超过255
#0 - #255 的范围。
所以,要表示#200,赋值200就可以了。
假设 Edit1.Text = '200' ,
AddrByte[5] := Byte( StrToInt( Edit1.Text ) )
//此时 AddrByte[5] = 200 = #200
 

to 提问者老兄,还有什么意见吗?
 
用Format函数啊
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
933
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
顶部