Forum > General

A constant array of records - Question

(1/2) > >>

neutrino70:
hi,
I've got a problem:

This is, what I declared:

type
  deckEnum = (ENG, FRA, GER, DIA);

  deckType = record
    PropSt: String;
    Fields: Byte;
    Stones: Byte;
    FreeFd: Byte;
    Moves:  Byte;
    Diags:  Byte;
  end;

const
  decks : array [deckEnum] of deckType = (
    (PropSt: 'ENG'; Fields: 33; Stones: 32; FreeFd: 16; Moves:  76; Diags: 60;),
    (PropSt: 'FRA'; Fields: 37; Stones: 36; FreeFd: 18; Moves:  92; Diags: 76;),
    (PropSt: 'GER'; Fields: 45; Stones: 44; FreeFd: 22; Moves: 108; Diags: 76;),
    (PropSt: 'DIA'; Fields: 41; Stones: 40; FreeFd: 20; Moves: 100; Diags: 92;)
  );
     
Question: How can I access the Stones-item in decks[DIA] (the 40 in the last line of decks)?

Please help

Paolo:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Deck[dia].stones Is enough

neutrino70:
Thanks you.
That was, what I thought. 

But Deck[dia].stones should read decks[DIA].Stones, isn't it?

But when I write :

decks[DIA].Stones, I get Error: Illegal expression

What is wrong? Please help

KodeZwerg:

--- Quote from: neutrino70 on February 02, 2023, 06:04:16 am ---But when I write :

decks[DIA].Stones, I get Error: Illegal expression
--- End quote ---
Can you tell how you write?
Can you enclose your codes in tags by clicking on the fancy [ # ] button?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;{$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF} type  TDeckEnum = (ENG, FRA, GER, DIA);   TDeckType = record    PropSt: String;    Fields: Byte;    Stones: Byte;    FreeFd: Byte;    Moves:  Byte;    Diags:  Byte;  end; const  CDecks : array [TDeckEnum] of TdeckType = (    (PropSt: 'ENG'; Fields: 33; Stones: 32; FreeFd: 16; Moves:  76; Diags: 60;),    (PropSt: 'FRA'; Fields: 37; Stones: 36; FreeFd: 18; Moves:  92; Diags: 76;),    (PropSt: 'GER'; Fields: 45; Stones: 44; FreeFd: 22; Moves: 108; Diags: 76;),    (PropSt: 'DIA'; Fields: 41; Stones: 40; FreeFd: 20; Moves: 100; Diags: 92;)  ); begin  WriteLn('Stoned: ', CDecks[DIA].Stones);  {$IFDEF MSWINDOWS}ReadLn; {$ENDIF}end.

TRon:

--- Quote from: neutrino70 on February 02, 2023, 06:04:16 am ---decks[DIA].Stones, I get Error: Illegal expression

What is wrong? Please help

--- End quote ---
That statement alone returns the value 40.

And that is all it does. it does not store it into another variable it does not feed the value to another function or otherwise. So you basically tell the compiler "40" and ask it to have fun with it  :)

To illustrate the statement you used does exactly the same as::

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---begin  40;end. 
Which does not make sense and so the compiler tells you.

After all, if it should work that way then only for the value 42  (the answer to anything in the universe) ;)

Navigation

[0] Message Index

[#] Next page

Go to full version