arbitrary number of parameters in procedure

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

arbitrary number of parameters in procedure

pianoman-3
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.
Thanx for help
Pianoman
----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, August 31, 2005 12:00 PM
Subject: fpc-pascal Digest, Vol 12, Issue 28


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:  set envirom variable with pascal in linux (Alain Vitry)
   2. Re:  set envirom variable with pascal in linux
      (Michael Van Canneyt)
   3. Re:  set envirom variable with pascal in linux (Marc Santhoff)
   4.  BMP support improved, feedback welcome. (Michael Van Canneyt)
   5. Re:  set envirom variable with pascal in linux (mondrillo)
   6. Re:  set envirom variable with pascal in linux (mondrillo)
   7.  Re: set envirom variable with pascal in linux (mondrillo)


----------------------------------------------------------------------

Message: 1
Date: Tue, 30 Aug 2005 12:16:29 +0200
From: Alain Vitry <[hidden email]>
Subject: Re: [fpc-pascal] set envirom variable with pascal in linux
To: FPC-Pascal users discussions <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

FYI, see
http://alain.vitry.free.fr/en/devel/devel-pascal.php

Le 30 août 05, à 08:47, mondrillo a écrit :

> Hello list,
>
> In Bach, Perl, can do set SDL_VER=`sdl-config --version`
> and in enviroment has the variable SDL_VER=1.2.3 for example.
> echo $SDL_VER
> 1.2.3
> But in Pascal non have the setenv() procedure as in C :(
>
> Actualy I resolve this problem with sending the output to a file, and
> then reading the file. But, can I pass from C this function?, or call
> a libc (thinks is this lib that has setenv() ) from Pascal to execute
> setenv().
>
> Thank's and regards.
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>




------------------------------

Message: 2
Date: Tue, 30 Aug 2005 11:13:30 +0200 (Romance Daylight Time)
From: Michael Van Canneyt <[hidden email]>
Subject: Re: [fpc-pascal] set envirom variable with pascal in linux
To: FPC-Pascal users discussions <[hidden email]>
Message-ID: <Pine.WNT.4.58.0508301110390.1216@home-office>
Content-Type: TEXT/PLAIN; charset=US-ASCII



On Tue, 30 Aug 2005, mondrillo wrote:

> Hello list,
>
> In Bach, Perl, can do set SDL_VER=`sdl-config --version`
> and in enviroment has the variable SDL_VER=1.2.3 for example.
> echo $SDL_VER
> 1.2.3
> But in Pascal non have the setenv() procedure as in C :(
>
> Actualy I resolve this problem with sending the output to a file, and
> then reading the file. But, can I pass from C this function?, or call
> a libc (thinks is this lib that has setenv() ) from Pascal to execute
> setenv().

That will not work.

FPC has a copy of the environment, which it received on startup.
It makes little or no sense to add strings to this, since it is
for internal use only.

If you want to execute another program with a different set of
environment strings, you must use the execve call to specify a
different set of environment variables.

The TProcess component allows you to easily specify the
environment as a TStringList.

Michael.



------------------------------

Message: 3
Date: Tue, 30 Aug 2005 14:53:43 +0200
From: Marc Santhoff <[hidden email]>
Subject: Re: [fpc-pascal] set envirom variable with pascal in linux
To: [hidden email]
Message-ID: <[hidden email]>
Content-Type: text/plain

Am Dienstag, den 30.08.2005, 08:47 +0200 schrieb mondrillo:

> Hello list,
>
> In Bach, Perl, can do set SDL_VER=`sdl-config --version`
> and in enviroment has the variable SDL_VER=1.2.3 for example.
> echo $SDL_VER
> 1.2.3
> But in Pascal non have the setenv() procedure as in C :(
>
> Actualy I resolve this problem with sending the output to a file, and
> then reading the file. But, can I pass from C this function?, or call
> a libc (thinks is this lib that has setenv() ) from Pascal to execute
> setenv().
>

If you're using a command line to execute a foreign program you can
always tell the shell:

csh: "setenv VAR value; your-foreign-program"
sh:  "VAR=value; your-foreign-program"

Not portable, ugly workaround, but it does do the job.

HTH,
Marc





------------------------------

Message: 4
Date: Tue, 30 Aug 2005 21:45:21 +0200 (CEST)
From: Michael Van Canneyt <[hidden email]>
Subject: [fpc-pascal] BMP support improved, feedback welcome.
To: [hidden email], FPC mailing list
<[hidden email]>
Message-ID: <[hidden email]>
Content-Type: TEXT/PLAIN; charset=US-ASCII

Hi,

Thanks to some excellent work from Giulio Berna, the support for BMP images
in the FCL has been greatly improved (and as such should impact Lazarus)

- BMP Reader enhanced to full Microsoft specs:
  + support for 15,16 bit bitmaps.
  + support for strange color masks at 16, 32 bpp
  + rle4 and rle8 decoding
  + top-down stored bitmaps.
  + Palette behaviour changed: use palette at 1,4,8 bits.
  + Support for OnProgress event.

- BMP Writer support:
  + BitsPerPixel property.
  + Writing at all color depths.
  + RLE8 and RLE4 compression.

I have applied his patches, but am not in the possibility to test all
these changes. If there are people out there which use a lot of images,
I would welcome some feedback.

More changes (dithering, quantizing) of images have also been implemented
by Giulio, and will be committed soon.

Kudos to Giulio Berna,

Enjoy,

Michael.



------------------------------

Message: 5
Date: Tue, 30 Aug 2005 22:37:13 +0200
From: mondrillo <[hidden email]>
Subject: Re: [fpc-pascal] set envirom variable with pascal in linux
To: FPC-Pascal users discussions <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=ISO-8859-1

Thanks, is the only think that I probe and runs ok!!!

****
program shell2;

uses baseunix, sysutils;
begin
    writeln('glx-config Version:',fpGetenv('SDL_VER'));
end.
****

export SDL_VER=`sdl-config --version`; ./shell2
glx-config Version:1.2.8

Note. I have put the clause EXPORT because I'm using bash.

I don't probe tu use the other method that other person has posted than
use a call to glibc, perhaps it's the largest walk.

Another one, has mentioned than FreePascal(FP) gives an enviroment in
read-only, I have read that the environ is an array of list of var's
with values, and I'dont know why FP (I love it) cannot write in this
array, perhaps do not implement yet.

Thank's eveybody, and regards.



El mar, 30-08-2005 a las 14:53 +0200, Marc Santhoff escribió:

> Am Dienstag, den 30.08.2005, 08:47 +0200 schrieb mondrillo:
> > Hello list,
> >
> > In Bach, Perl, can do set SDL_VER=`sdl-config --version`
> > and in enviroment has the variable SDL_VER=1.2.3 for example.
> > echo $SDL_VER
> > 1.2.3
> > But in Pascal non have the setenv() procedure as in C :(
> >
> > Actualy I resolve this problem with sending the output to a file, and
> > then reading the file. But, can I pass from C this function?, or call
> > a libc (thinks is this lib that has setenv() ) from Pascal to execute
> > setenv().
> >
>
> If you're using a command line to execute a foreign program you can
> always tell the shell:
>
> csh: "setenv VAR value; your-foreign-program"
> sh:  "VAR=value; your-foreign-program"
>
> Not portable, ugly workaround, but it does do the job.
>
> HTH,
> Marc
>
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



------------------------------

Message: 6
Date: Wed, 31 Aug 2005 08:26:40 +0200
From: mondrillo <[hidden email]>
Subject: Re: [fpc-pascal] set envirom variable with pascal in linux
To: FPC-Pascal users discussions <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=ISO-8859-1

Thank's for the page

El mar, 30-08-2005 a las 12:16 +0200, Alain Vitry escribió:

> FYI, see
> http://alain.vitry.free.fr/en/devel/devel-pascal.php
>
> Le 30 août 05, à 08:47, mondrillo a écrit :
>
> > Hello list,
> >
> > In Bach, Perl, can do set SDL_VER=`sdl-config --version`
> > and in enviroment has the variable SDL_VER=1.2.3 for example.
> > echo $SDL_VER
> > 1.2.3
> > But in Pascal non have the setenv() procedure as in C :(
> >
> > Actualy I resolve this problem with sending the output to a file, and
> > then reading the file. But, can I pass from C this function?, or call
> > a libc (thinks is this lib that has setenv() ) from Pascal to execute
> > setenv().
> >
> > Thank's and regards.
> >
> >
> > _______________________________________________
> > fpc-pascal maillist  -  [hidden email]
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> >
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



------------------------------

Message: 7
Date: Wed, 31 Aug 2005 08:34:42 +0200
From: mondrillo <[hidden email]>
Subject: [fpc-pascal] Re: set envirom variable with pascal in linux
To: Jeff Pohlmeyer <[hidden email]>
Cc: [hidden email]
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=ISO-8859-1

Thank's for the response, perhaps it's my arch ( amd64 ) and compiler
2.0.0, but when I  execute this code say :

./sdlver
1.5426178.-248

if I execute `$sdl-config --version` output is not the same :(
1.2.8


El mar, 30-08-2005 a las 08:23 -0500, Jeff Pohlmeyer escribió:

>
> > In Bach, Perl, can do set SDL_VER=`sdl-config --version`
> > But in Pascal non have the setenv() procedure as in C :(
> > ...
> > Actualy I resolve this problem with sending the output to a file,
> and
> > then reading the file.
>
> It sounds to me like you just want a global
> variable, not an environment variable.
>
> Maybe something like this?
>
> (************************************)
> program sdlver;
>
> uses libc;
>
> type
>   SDL_version = record
>     major : byte;
>     minor : byte;
>     patch : byte;
>   end;
>   pSDL_version = ^SDL_version;
>
> function SDL_Linked_Version:pSDL_version; cdecl; external 'SDL';
>
> var
>   SDL_VER:array[0..15] of char;
>
> begin
>   with SDL_Linked_Version^ do sprintf(SDL_VER, '%d.%d.%d', [major,
> minor, patch]);
>   WriteLn(SDL_VER);
> end.
> (************************************)
>
>
> Regards,
>  - Jeff
>



------------------------------

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


End of fpc-pascal Digest, Vol 12, Issue 28
******************************************


__________ Informacia od NOD32 1.1205 (20050830) __________

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: arbitrary number of parameters in procedure

Michael Van Canneyt


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