Problem z deklaracją stałej tablicy w tablicy

0

Witam.

W osobnym unitcie chcę stworzyć tablicę stałych wartośći. A nie wiem jak zrobić aby poniższy kod zadziałął. Prosił bym
o jakiś przykład co wstawić w miejsce "???" żeby się skompilowało. Chodzi mi o coś takiego żę TWItemDesc.Col będzie
równe sześć, a następnie będzie tablica TItemList [0..7] i w niej elementy Txt: 'None'; IRes: 0; później drugi element ma
mieć Txt: 'Personnel" IRes: 1; i tak dalej. Po czym kolejny element tablicy TWItemDesc w analoficzny sposób ale już
TItemList może mieć inną ilośc elementów. a i przy okazji jeszcze jedno pytanie czy można zadeklarować taką stałą
const A : TStringList = i jak to później wypełenić czy się nie da w Delphi? Poniżej kodu z "???" obecny mój zły sposób.

type
  TItemRec = record
    Txt : string;
    IRes : integer;
  end;
  TItemList = array of TItemRec;

  TWItemDesc = record
    Col : integer;
    Itms : TItemList
  end;

const
  Tab : array[1..3] of TWItemDesc =
  (
  (Col: 0;
  Itms : ???)
  );

begin
end;

Może uproszczę na przykładzie, teraz mam tymczasowo taki kod jak poniżej. Jak wiadomo jest on
w ogółe nieoptymalny oraz mało elastyczny. Jak właśnie to można uprościć aby nie trzeba było w
stałcyh definiować dówch osobnych tablic, tylko zrobić tak aby mieć wszystko w jednej tablicy, ale
z możliwością przechowania numeru kolumny i listą o róznej ilości rekordów TWeapVal. Da się i jak?

type
  TWeapVal = record
    R : integer;
    T : string;
  end;

const
  WeapCol6 : array[0..7] of TWeapVal =
  (
    (R : 0; T : 'None'),
    (R : 1; T : 'Personnel'),
    (R : 2; T : 'Vehicle'),
    (R : 3; T : 'Vehicle & Personnel'),
    (R : 4; T : 'Terrain'),
    (R : 5; T : 'Personnel & Terrain'),
    (R : 6; T : 'Vehicle & Terrain'),
    (R : 7; T : 'All')
    );

  WeapCol18 : array[0..1] of TWeapVal =
  (
    (R : 0; T : 'False'),
    (R : 1; T : 'True')
    );

procedure GenerateWeapComboList(Col : integer; var Combo : TComboBox);

implementation

procedure GenerateWeapComboList(Col : integer; var Combo : TComboBox);
var
  I : Byte;
begin
  case Col of
    6 :
      begin
        Combo.Clear;
        for I := Low(WeapCol6) to High(WeapCol6) do
        begin
          Combo.Items.AddObject(WeapCol6[I].T, TOBject(WeapCol6[I].R));
        end;
      end;
    18 :
      begin
        Combo.Clear;
        for I := Low(WeapCol18) to High(WeapCol18) do
        begin
          Combo.Items.AddObject(WeapCol18[I].T, TOBject(WeapCol18[I].R));
        end;
      end;
  end;
end;

end.
0

Już sobie poradziłem w taki sposób jak poniżej. No właśnie ale teraz operuje na zmiennych, a nie
stałych no i muszę używać także tablic dynamicznych, którym nadaję długość, ale czy da się w Delphi 7
zrobić to tak, jak próbowałem wcześniej przy użyciu stałych i bez używania tablic dynamicznych w ogóle
podając ilość Items? Bo jak jest taka możliwość nie musiał bym korzystać z tablic dynamicznych wcale.

type
  TItemRec = record
    R : integer;
    T : string;
  end;

  TItemList = array of TItemRec;

  TItemDesc = record
    Col : integer;
    Descr : string;
    Items : TItemList
  end;

var
  WeapArray : array[1..3] of TItemDesc;

procedure GenerateWeapChoose(Col : integer; var Combo : TComboBox; var Memo : TMemo);

implementation

procedure GenerateWeapChoose(Col : integer; var Combo : TComboBox; var Memo : TMemo);
var
  I, J : Byte;
begin
  Combo.Clear;
  Memo.Clear;
  for I := Low(WeapArray) to High(WeapArray) do
  begin
    if WeapArray[I].Col = Col then
    begin
      for J := Low(WeapArray[I].Items) to High(WeapArray[I].Items) do
      begin
        Combo.Items.AddObject(WeapArray[I].Items[J].T, TOBject(WeapArray[I].Items[J].R));
        Memo.Text := WeapArray[I].Descr;
      end;
      Exit;
    end;
  end;
end;

begin
  SetLength(WeapArray[1].Items, 8);
  SetLength(WeapArray[2].Items, 2);
  SetLength(WeapArray[3].Items, 5);

  WeapArray[1].Col := 6;
  WeapArray[1].Descr := 'Valid targets';
  WeapArray[1].Items[0].R := 0; WeapArray[1].Items[0].T := 'None';
  WeapArray[1].Items[1].R := 1; WeapArray[1].Items[1].T := 'Personnel';
  WeapArray[1].Items[2].R := 2; WeapArray[1].Items[2].T := 'Vehicle';
  WeapArray[1].Items[3].R := 3; WeapArray[1].Items[3].T := 'Vehicle & Personnel';
  WeapArray[1].Items[4].R := 4; WeapArray[1].Items[4].T := 'Terrain';
  WeapArray[1].Items[5].R := 5; WeapArray[1].Items[5].T := 'Personnel & Terrain';
  WeapArray[1].Items[6].R := 6; WeapArray[1].Items[6].T := 'Vehicle & Terrain';
  WeapArray[1].Items[7].R := 7; WeapArray[1].Items[7].T := 'All';

  WeapArray[2].Col := 18;
  WeapArray[2].Descr := 'Can the weapon be fired while moving?';
  WeapArray[2].Items[0].R := 0; WeapArray[2].Items[0].T := 'False';
  WeapArray[2].Items[1].R := 1; WeapArray[2].Items[1].T := 'True';

  WeapArray[3].Col := 111;
  WeapArray[3].Descr := 'How weapon is mounted from Weapon Mount table.';
  WeapArray[3].Items[0].R := 0; WeapArray[3].Items[0].T := 'Main';
  WeapArray[3].Items[1].R := 1; WeapArray[3].Items[1].T := 'Hull';
  WeapArray[3].Items[2].R := 2; WeapArray[3].Items[2].T := 'Coax)';
  WeapArray[3].Items[3].R := 3; WeapArray[3].Items[3].T := 'AA';
  WeapArray[3].Items[4].R := 4; WeapArray[3].Items[4].T := 'Rear';
end.

1 użytkowników online, w tym zalogowanych: 0, gości: 1