这个数组数据为:010302050102030405060702030205010203040506070103020501020304050607010302050102030405060701030205010203040506070103020501020304050607
我现在需要如何遍历这个数组
把绿色的显示在第一列
把红色的显示在第二列
第一列 第二列
1 01030205 01020304050607
2 02030205 01020304050607
3 01030205 01020304050607
4 04030205 01020304050607
5 01030205 01020304050607。
第一列的数据可能相同,也可能不同,第二列也是
请问大神如何做?
我现在需要如何遍历这个数组
把绿色的显示在第一列
把红色的显示在第二列
第一列 第二列
1 01030205 01020304050607
2 02030205 01020304050607
3 01030205 01020304050607
4 04030205 01020304050607
5 01030205 01020304050607。
第一列的数据可能相同,也可能不同,第二列也是
请问大神如何做?
procedure TForm1.Button1Click(Sender: TObject);
var
aItem: TListItem;
i, n, m: integer;
s1, s2: string;
a: array[0..600]of byte;
begin
s1 := '010302050102030405060702030205010203040506070103020501020304050607010302050102030405060701030205010203040506070103020501020304050607';
for i := 0 to Length(s1) - 1 do
a[i] := StrToInt(s1[i+1]); i := 0;
n := Length('01030205');
s1 := '';
s2 := '';
m := 0;
while i < Length(a) do
begin
if m = 0 then
begin
if Length(s1) < n then
s1 := s1 + IntToStr(a[i])
else
begin
m := 1;
n := Length('01020304050607');
end;
end
else
begin
if Length(s2) < n then
s2 := s2 + IntToStr(a[i])
else
begin
aItem := ListView1.Items.add;//Show String TO ListView
aItem.Caption := s1;
aItem.SubItems.Add(s2); //Clear Params
s1 := '';
s2 := '';
m := 0;
n := Length('01030205');
end;
end; inc(i);
end;
if (s1 <> '') or (s2 <> '') then
begin
aItem := ListView1.Items.add;
aItem.Caption := s1;
aItem.SubItems.Add(s2);
end;
end;
行数可以这样确定:
ipos:=trunc(Length(a)/13); 第一位08(这个代表的是后面00 01 02 03 04 05 06 07 返回的数据大小)
如果是07(则后面返回的数据是00 01 02 03 04 05 06 00)
var
aItem: TListItem;
i, n, m, k: integer;
s1, s2: string;
a: array[0..649]of byte;
begin
s1 := '010302050102030405060702030205010203040506070103020501020304050607010302050102030405060701030205010203040506070103020501020304050607';//自己重新整理数组
for i := 0 to Length(s1) - 1 do
a[i] := StrToInt(s1[i+1]);
i := 0;
//n := Length('01030205');
n := 5;//从08开始读5Byte
s1 := '';
s2 := '';
m := 0;
while i < Length(a) do
begin
if m = 0 then
begin
if Length(s1) < n then
s1 := s1 + IntToStr(a[i])
else
begin
m := 1;
//n := Length('01020304050607');
n := 8;//不管前面是07还是08,都读8位,看你说的数据结构,不管是07还是08,后面都是8位啊
end;
end
else
begin
if Length(s2) < n then
s2 := s2 + IntToStr(a[i])
else
begin
aItem := ListView1.Items.add;//Show String TO ListView
aItem.Caption := s1;
aItem.SubItems.Add(s2);
//Clear Params
s1 := '';
s2 := '';
m := 0;
//n := Length('01030205');
n := 5;//从08开始读5Byte
end;
end;
inc(i);
end;
if (s1 <> '') or (s2 <> '') then
begin
aItem := ListView1.Items.add;
aItem.Caption := s1;
aItem.SubItems.Add(s2);
end;
end;
我贴下源码:后来想想13位13去取FillChar(CanData,SizeOf(CanData),0);
Move(cmd.CMD_H.CANDATAGET.data,CanData,SizeOf(cmd.CMD_H.CANDATAGET.data)); iLen:=Length(candata);
m:=0;
n:=0; j:=0;
repeat
m:=CanData[j] and $f;
s1:='';
for n:=j+1 to j+4 do
begin
s1:=s1+inttohex(CanData[n],2); //第一列
end;
item:=lv1.items.add;
item.caption:=inttostr(j);
item.subitems.add(s1);
s2:='';
for n:=j+5 to j+4+m do
begin
s2:=s2+inttohex(CanData[n],2);
end;
Item.SubItems.Add(s2); inc(j,13);
until
j=iLen;