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

Jiří Pavlovský jira at getnet.cz
Mon Dec 26 20:19:23 CET 2011


On 26.12.2011 12:50, Howard Page-Clark wrote:
> 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).


Yes, sorry I should have been more clear. It was late evening and I got 
frustrated...

I now got what I need working. Still if there is a way to make it more 
concise, Please let me know.


{$mode objfpc}
uses  fgl;

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

MyIntType = byte;
TArrayType = array of TMyRec;

TSubMyMap = specialize TFPGMap<Char, TArrayType>;
TMyMap = specialize TFPGMap<Char,TSubMyMap>;

var t : TMyMap;
  r : TMyRec;
  myArray : TArrayType;

begin
r.Start := 1; r.Stop := 2;
SetLength(myArray, 1);
myArray[0] := r;

t:= TMyMap.Create;
t['a'] := TSubMyMap.Create;
t['a']['b'] := myArray;

writeln(t['a']['b'][0].Start);

end.






More information about the fpc-pascal mailing list