[fpc-pascal] Re: Re: arbitrary number of parameters in procedure
Pianoman
pianoman at centrum.sk
Sun Sep 4 10:52:03 CEST 2005
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: <fpc-pascal-request at lists.freepascal.org>
To: <fpc-pascal at lists.freepascal.org>
Sent: Friday, September 02, 2005 3:28 PM
Subject: fpc-pascal Digest, Vol 13, Issue 1
> Send fpc-pascal mailing list submissions to
> fpc-pascal at lists.freepascal.org
>
> 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
> fpc-pascal-request at lists.freepascal.org
>
> You can reach the person managing the list at
> fpc-pascal-owner at lists.freepascal.org
>
> 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 <michael at freepascal.org>
> Subject: Re: [fpc-pascal] arbitrary number of parameters in procedure
> To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
> Message-ID: <Pine.LNX.4.61.0508312250200.15962 at home.wisa.be>
> 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 - fpc-pascal at lists.freepascal.org
> 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
>
>
More information about the fpc-pascal
mailing list