[fpc-pascal] Partially initializing array of records
Rainer Stratmann
RainerStratmann at t-online.de
Tue Jul 19 19:54:00 CEST 2011
Am Tuesday 19 July 2011 19:44:17 schrieb Clay Stuart:
> Hello Everyone:
>
> I've got an array of records that looks something like this:
>
> type
> node = record
> foo : array[1..10] of integer;
> bar : array[1..10] of integer;
> end
>
> var
> graph : array[1..5] of node;
>
> begin...
>
>
> However, the arrays hold different amounts of numbers. So node[1].foo
> might hold 5 numbers while node[2].foo might hold only 2.
>
> My Question...
> Is there a way to initialize these numbers somehow. It seems the compiler
> won't allow me to partly fill the arrays. If I use them, it appears I have
> to use them all the way.
>
> Thank you in advance,
> Clay
I would do it like this.
const cntmax = 5;
var cnt : longint;
procedure init_counter;
begin
cnt := 0;
end;
procedure init( v1 , v2 , v3 , v4 , v5 , v6 , v7 , v8 , v9 , v10 : integer );
begin
if cnt < cntmax then begin
with graph[ cnt ] do begin
foo[ 1 ] := v1;
foo[ 2 ] := v2;
...
foo[ 10 ] := v10;
end;
inc( cnt );
end;
end;
init_counter;
init_arr( 34 , 56 , 33 , 44, 44, 56, .. , .. , .., 77 );
init_arr( 34 , 56 , 33 , 44, 44, 56, .. , .. , .., 77 );
init_arr( 34 , 56 , 33 , 44, 44, 56, .. , .. , .., 77 );
init_arr( 34 , 56 , 33 , 0,0,0,0,0,0,0 );
More information about the fpc-pascal
mailing list