求解释delphi中Olevariant类型使用?
在写串口的CRC校验中使用到这样的函数:Function CRC8(buffer:Olevariant;len:byte):byte;
var
i,crc:byte;
shu:byte;
begin
crc:=0;
shu:=0;
while len<>0do
begin
len:=len-1;
i:=1;
while i<>0 do
begin
if ((crc and $01)<>0)then
crc := (crc shr 1) xor $8c // 最低位为1,移位和异或处理
else
crc := crc shr 1; // 否则只移位(除2)
if ((bufferand i)<>0) then
crc:=crc xor $8c;
i:=i*2;
end;
shu:=shu+1;
end;
CRC8:=crc;
end;
现在有一字符串类型要进行CRC校验,但是数据类型为string。
string咋转换为Olevariant。 直接 用 pchar转换 试试
页:
[1]