[fpc-pascal] Procedures that work like WRITELN()

Thomas Kurz fpc.2021 at t-net.ruhr
Wed Dec 27 12:46:45 CET 2023


I think he wants to define his own procedure.

The nearest thing that comes into my mind is using ARRAY OF CONST, but the call requires square brackets, then:

procedure myproc (x: string; y: array of const);
begin ... end;

myproc ('Hello world', ['Number 1', 'Number 2', 3, 4.0]);


----- Original Message ----- 
From: Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org>
To: james at productionautomation.net <james at productionautomation.net>
Sent: Wednesday, December 27, 2023, 12:40:24
Subject: [fpc-pascal] Procedures that work like WRITELN()



On Wed, 27 Dec 2023, James Richters via fpc-pascal wrote:

> I wanted to write what I thought should be a simple procedure, just instead
> of calling WRITELN() with some arguments,
> call WRITELOG() with the same arguments that you would use to write to a
> file, but my WRITELOG() procedure would
> write to the screen and the file.. but I can't figure out how to pass all
> the arguments to the two WRTIELNs.

> So..

> Procedure WriteLog(Filename:String, AllOtherAurguments:????);
> Begin
>    Writeln(Filename,AllOtherAurguments);
>    Writeln(AllOtherAurguments);
> End;

> How can I make this work?  Since WRITELN can take any number of many kinds
> of arguments,
> how can I get them all and pass them along without knowing how many or what
> types they are?
> How does WRITELN even work when you don't know this information?

> I'm guessing there should be some way to do this, because WRITELN itself
> works, but how it could
> possibly work is not within my experience.

> The only way I could think of would be if there were versions of WRITELN
> with every combination
> of possible arguments, but that seems completely unmanageable and
> ridiculous,
> so there must be something more advanced going on, but maybe WRTELN is
> special and not something I can duplicate?

Writeln() is special. You cannot duplicate it.

What you can do is use WriteStr(), it has the same action as Writeln() but
writes to a string instead of a file.

https://www.freepascal.org/docs-html/current/rtl/system/writestr.html

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list