Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-09

Re: Re: arbitrary number of parameters in procedure

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Pianoman
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:
To:
Sent: Friday, September 02, 2005 3:28 PM
Subject: fpc-pascal Digest, Vol 13, Issue 1

Show quoted text 83 lines
Send fpc-pascal mailing list submissions to 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 You can reach the person managing the list at 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 Subject: Re: [fpc-pascal] arbitrary number of parameters in procedure To: FPC-Pascal users discussions Message-ID: 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 - 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
Michael Van Canneyt
to Pianoman
Pianoman wrote 8 lines
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.