[fpc-pascal] Map of values to array of records

Howard Page-Clark hdpc at talktalk.net
Mon Dec 26 12:50:00 CET 2011


On 25/12/11 10:07, Jiří Pavlovský wrote:

>> What do you mean ?
> I mean the code below works ok, so I don't undestand why it doesn't
> compile when I use similar construct inside a function.
> const ranges: array [1..2] of TMyRec =
>       (
>           (Start:    0;    Stop:    3),
>           (Start:    4;    Stop:    7)
>         );

Are you looking for something like this? (BTW your code snippets are too 
short to really understand what you can't do).

type
   TMyRec = record
     Start, Stop: integer;
   end;

TRange = array [1..2] of TMyRec;

const RANGES: TRange =
      (
          (Start:    0;    Stop:    3),
          (Start:    4;    Stop:    7)
        );

function GetRec(anIndex: integer): TMyRec;
begin
   result := RANGES[anIndex];
end;



More information about the fpc-pascal mailing list