[fpc-pascal] Pass array of record as parameter

Thomas Young tygraphics at me.com
Fri Feb 10 01:34:06 CET 2012


Howard are you saying FPC has dynamic arrays? Is it documented? I've been reading the documentation page by page and I've not seen any mention of it. I'm far from completing the reading by the way.

If dynamic arrays are part of FPC I couldn't be more delighted. I don't completely understand what they are exactly. Would I be right in saying they have the advantages of a linked list without the loss of speed that I so enjoy with arrays? Maybe linked lists are slow for me because of the way I wrote the code. The problem I have with arrays is that I often parse postscript vector art files. These files have to be read in a discovery mode approach because I don't know how many paths I will encounter nor know how many vertices will be in a path. As a result arrays are large enough to accommodate the largest path but are way overkill for a simple path.

My hope would be that I could use a dynamic array to hold just the number of vertices I discover in a path.

Thanks for sharing the code in your post. It fascinates me.

I'm eager to learn all I can about about the amazing things that can be done with FPC. To all those who have been building FPC, thank you. While I have been programming in pascal since 1986 almost daily I've relied on the basic features of the language. Time to stretch my mind.


Thomas Young
cell: 330-256-7064
mobile email: tygraphics at me.com



On Feb 9, 2012, at 1:08 PM, Howard Page-Clark wrote:
> 
> You have to declare the parameter type independently of the function declaration. You can also do it without declaring an additional pointer type (which is also one way to do it), since dynamic arrays already have an implicit pointer. Something like this:
> 
> type
>  TInfo=record
>    s: string;
>    i: integer;
>  end;
> 
>  TInfoArr = array of tInfo;
> 
> procedure proc1(a: TInfoArr);
> 
> implementation
> 
> procedure TForm1.Button1Click(Sender: TObject);
> var rec: TInfo;
>    infoArr: TInfoArr = nil;
> begin
>  SetLength(infoArr, 2);
>  rec.i := 1; rec.s := 'test1';
>  infoArr[0] := rec;
>  rec.i := 2; rec.s := 'test2';
>  infoArr[1] := rec;
>  proc1(infoArr);
> end;
> 
> procedure proc1(a: TInfoArr);
> var s: string = '';
>    i: integer;
> begin
>  for i := Low(a) to High(a) do
>   s := s + Format('TInfo%d: s=%s, i=%d ',[i, a[i].s, a[i].i]);
>  Showmessage(s);
> end;
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120209/832106cb/attachment.html>


More information about the fpc-pascal mailing list