-1

I'm basically coding some sort of table where for column tags I have some numbers and for row tags I have some strings which contain such numbers separated by commas.

I'm taking all the row tags from a TString named minterms_essentials and the column tags from one named minterms.

First I must tag the created 2 dimensions array. And then, if any string from the rows contains certain letter, I must place an 'x' in the proper column.

I've wrote this Delphi code but I'm getting access violation so far...

SetLength(tabla, minterms_essentials.Count+1,minterms.Count+1);

for i := 0 to minterms.Count-1 do
begin
  tabla[0,i+1] := IntToStr(BinToInt(minterms[i]));
end;

for i := 0 to minterms_essentials.Count-1 do
begin
  tabla[i+1,0] := minterms_essentials[i];
end;

for i := 1 to minterms_essentials.Count-1 do
begin
for g := 1 to minterms.Count-1 do
  begin
    ss := tabla[g,0].Split([',']);
    for s in ss do
      begin
        if s = tabla[0,g] then
          begin
            tabla[g,i] := 'x';
          end;
      end;
  end;
end; 

Is there any better and correct way to do this?

4

1 回答 1

5

看这个:

第一个维度由minterms_essentials定义

SetLength(tabla, minterms_essentials.Count+1,minterms.Count+1);

但在这里你使用minterms来索引数组的第一维:

for g := 1 to minterms.Count-1 do
  begin
    ss := tabla[g,0].Split([',']);

附言。你还没有打开范围检查吗?

于 2013-06-26T06:04:58.330 回答