Re: Re: arbitrary number of parameters in procedure

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Re: arbitrary number of parameters in procedure

pianoman-3
Hi Michael, I tested your proc but it don't want to ccompile .
program follows:
program test;
var a,b,c,d:integer;
res:double;


Procedure AddNums(Var Result : Double; Args : Array of integer);
Var
  I : Integer;

begin
  Result:=0;
  For I:=0 to High(Args) do // High(args) is the last valid index.
   Case Args[i].Vtype of // args[i] is of type TVarRec
     VtInteger : Result:=Result+Args[ArgPos].VInteger;
    // ... etc
   end;
end;
begin
readln(a,b,c,d);



  AddNums(vysledok,[a,b,c,d]);

end.

-
And one more question the header of procedure looks like addnums(var result,
and ind square brackets the other params but what if I want all params to be
in normal () like in writeln?
Thanx
Pianoman---- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Friday, September 02, 2005 3:28 PM
Subject: fpc-pascal Digest, Vol 13, Issue 1


> Send fpc-pascal mailing list submissions to
> [hidden email]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> or, via email, send a message with subject or body 'help' to
> [hidden email]
>
> You can reach the person managing the list at
> [hidden email]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of fpc-pascal digest..."
>
>
> Today's Topics:
>
>    1. Re:  arbitrary number of parameters in procedure
>       (Michael Van Canneyt)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 31 Aug 2005 22:57:30 +0200 (CEST)
> From: Michael Van Canneyt <[hidden email]>
> Subject: Re: [fpc-pascal] arbitrary number of parameters in procedure
> To: FPC-Pascal users discussions <[hidden email]>
> Message-ID: <[hidden email]>
> Content-Type: TEXT/PLAIN; charset=US-ASCII
>
>
>
> On Wed, 31 Aug 2005, Pianoman wrote:
>
> > Hi, I have not well understood the docs concerning tvarrecs. How can I
> > create procedure which will accept arbitrary number of parameters?
> > To demonstrate what I want:
> > procedure addnums(a,b,c,xxxx of any types var result:sometype);
> > or writetoscreen(any number of parameters of given type. something like
> > write or readln procedures.
>
> Something like this:
>
> Procedure AddNums(Var Result : Double; Args : Array of const);
>
> Var
>   I : Integer;
>
> begin
>   Result:=0;
>   For I:=0 to High(Args) do // High(args) is the last valid index.
>    Case Args[i].Vtype of // args[i] is of type TVarRec
>      VtInteger : Result:=Result+Args[ArgPos].VInteger;
>     // ... etc
>    end;
> end;
>
> Call like
>
>   AddNums(MyDouble,[a,b,c,d]);
>
> And you're all done.
>
> Michael.
>
> ------------------------------
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
> End of fpc-pascal Digest, Vol 13, Issue 1
> *****************************************
>
>
> __________ Informacia od NOD32 1.1208 (20050902) __________
>
> Tato sprava bola preverena antivirusovym systemom NOD32.
> http://www.eset.sk
>
>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: arbitrary number of parameters in procedure

Michael Van Canneyt


On Sun, 4 Sep 2005, Pianoman wrote:

> Hi Michael, I tested your proc but it don't want to ccompile .
> program follows:
> program test;
> var a,b,c,d:integer;
> res:double;
>
>
> Procedure AddNums(Var Result : Double; Args : Array of integer);

This must be "array of const", not "Array of integer".

Michael.

> -
> And one more question the header of procedure looks like addnums(var result,
> and ind square brackets the other params but what if I want all params to be
> in normal () like in writeln?

You can't have that.
Writeln() and Readln() are anomalies, and require special compiler magic.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal