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

ik idokan at gmail.com
Sun Dec 25 22:53:46 CET 2011


2011/12/25 Jiří Pavlovský <jira at getnet.cz>

> Hello,
>
> how can I create two level map where value is array of  records? These
>  records are constant - I don't need to compute them or anything.
> I'm quite new to pascal and for gods sake cannot figure it out. I tried to
> use TFPGMap for that.
>
> I mean somewhere in the code I get two values and based on these I need to
> get those records.
>
> my dream would be something like
> myArrayOfRecords := myMap[some_value][other_value]**;
>

type
   TMyRec = record
     Field   : integer;
     Empty,
    Check : Boolean;
   end;

 TMyMap = array[0..Something] of TMyRec;


>
>
> I even tried to write a function that would return array of records based
> on its parameters, but that does not work either.
> I cannot figure out how to assign the record.
>
> This causes a compile error:
> res[0] := (Field: 1; Empty: true; Check: false);
>

 res[0].Field := 1;
 res[0].Empty := true;
 res[0].Check := false;

if you want to make it as a function:

function ToMyRec (AField : Integer; AEmpty, ACheck : Boolean) : TMyRec;
begin
   Result.Field := AFiled;
   Result.Empty :=  AEmpty;
   Result.Check := AChek;
end;

res[0] := ToMyRec(...);


>
>
> OTOH similar construct works in "const" section. So I'm quite puzzled.
>

What do you mean ?


>
>
> Thank you
> ______________________________**_________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111225/b69ff7af/attachment.html>


More information about the fpc-pascal mailing list