[fpc-pascal]Minimum size of parameters

Jonas Maebe jonas at zeus.rug.ac.be
Thu Dec 6 18:34:00 CET 2001


On donderdag, december 6, 2001, at 05:42 , Aitor Santamaria Merino wrote:

> This would be, then
> RECORD
>      Pt: Procedure (args: array of const);
>      Arg: args;
> END;
> right?

I suppose you mean "args: array of const". But that won't work, an 
"array of const" can only be an argument, not a variable type. I also 
didn't realise you wanted to store the arguments together with the 
procedure to call, because in that case you can't use an array of const. 
You'll have to create your own variant type (FCP variant support isn't 
complete yet), like this:

***
{$mode objfpc}

type
   tmyvariant = record
     case typ: longint of
       0: (i: integer);
       1: (s: string);
   end;

   tproccallrec = record
     pt: procedure (const args: array of tmyvariant);
     args: array of tmyvariant;
   end;

procedure test(const a: array of tmyvariant);
begin
   writeln(high(a));
   writeln(a[0].i);
end;

var
   pcr: tproccallrec;
   v: tmyvariant;
begin
   pcr.pt := @test;
   setlength(pcr.args,2);
   v.typ := vtInteger; { you can also create your own constants for
denoting the type, but since these already exist... }
   v.i := 5;
   pcr.args[0] := v;
   v.typ := vtString;
   v.s := 'test';
   pcr.args[1] := v;
   pcr.pt(pcr.args);
end.
***

Note however that

a) you need a 1.1 snapshot to compile this
b) it DOES NOT WORK :)

The reason for b is that there are apparently bugs in the compiler for a 
conversion of a "dynamic array" to an open array...

>> I suppose this is all explained in the reference manual, though I'm 
>> not sure.
>
> I coulnd't find it as a first glance... (I looked at the open arrays 
> section, although my compiler version is still rather outdated...

An "array of const" is something completely different from an "open 
array" (and both are different from a "dynamic array"). I assume "array 
of const" will only be explained in the 1.1 manual.


Jonas





More information about the fpc-pascal mailing list