你说的不是很清楚,你参考这点代码吧,
const no:Integer=26; //数组长度
implementation
var d:array[1..26] of Byte=($FF,05,01,01,$1E,
01,$32,05,01,$FF,
01,$1F,07,01,$FF,
01,$1E,07,01,$FF,
01,$1F,07,01,$FF,01);
d1:array[1..100] of Byte;
new_len:Integer; //新数组长度
{$R *.dfm}
{
FF 05 01 01 1E 01 32 05 01 FF 01 1F 07 01 FF 01 1E 07 01 FF 01 1F 07 01 FF 01
如果是 FF 05 就读取 FF 05之后的5个字节 。 然后就不管吗???
05 01 就分解成 01 01 01 01 01
例子 FF 05 01 01 1E 01 32 05 01 //这里已经超过5个字节??
就分解成 01 01 1E 01 32 01 01 01 01 01
}
{
代码运行的结果:
01 01 1E 01 32 01 01 01 01 01 FF 01 1F 07 01 FF 01 1E 07 01 FF 01 1F 07 01 FF 01 }
procedure TForm1.Button1Click(Sender:TObject);
var i,j:Integer;
flag:Boolean;
tstr:string;
begin
new_len:=0;
flag:=false; //符合条件标志
i:=0;
repeat
Inc(i);
if (d=$FF)and(d[i+1]=$05) then
begin
flag:=true; //符合条件标志 ....已经有数据符合条件,查找后面的数据是不是有符合05 01的数据,如果有就分解
i:=i+2; //避开$ff $05
end;
if flag then //符合条件标志 ....已经有数据符合条件,查找后面的数据是不是有符合05 01的数据,如果有就分解
begin
if (d=$05)and(d[i+1]=$01) then
begin
Inc(i);
for j:=1 to 5 do //分解数据 ..本身一位01,所以加上4个01就可以
begin
Inc(new_len);
d1[new_len]:=$01;
end;
end
else
begin
Inc(new_len);
d1[new_len]:=d;
end;
end;
until i>=no;
tstr:='';
for i:=1 to new_len do
tstr:=tstr+IntToHex(d1,2)+' ';
Edit1.text:=tstr;
end;