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

Sven Barth pascaldragon at googlemail.com
Wed Dec 27 16:52:01 CET 2023


Am 27.12.2023 um 12:25 schrieb James Richters via fpc-pascal:
>
> 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?
>

Write(Ln) is a compiler intrinsic and thus can behave in ways that are 
not possible for ordinary functions.

Your only ways are either to use "array of const" like "Format" does or 
write a text file driver as is done in the StreamIO unit which allows to 
assign a Stream to a TextFile that can in turn be used as the file 
parameter of Write(Ln). You can implement any other output through this.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20231227/8f38daec/attachment-0001.htm>


More information about the fpc-pascal mailing list