[fpc-pascal] redirecting stdout

Sven Barth pascaldragon at googlemail.com
Sun Jul 18 17:36:28 CEST 2010


Hi!

On 18.07.2010 17:07, Bernd wrote:
> But I do not understand the following:
>
> function TStream.Write(const Buffer; Count: Longint): Longint;
>
> what type is Buffer? How does it get away with the missing type
> declaration without the compiler failing to compile this at all?

Quote from the Docs ( 
http://www.freepascal.org/docs-html/ref/refsu54.html#x134-14100011.4.2 ):

Variable and constant parameters can be untyped. In that case the 
variable has no type, and hence is incompatible with all other types. 
However, the address operator can be used on it, or it can be can passed 
to a function that has also an untyped parameter. If an untyped 
parameter is used in an assigment, or a value must be assigned to it, a 
typecast must be used.

===

You pass a variable of any type you like into such a parameter. 
Basically you can think of it as a Pointer where you're not allowed to 
pass Nil (because you're passing the location of a variable).

For an example usage see the other Write* methods of TStream: they pass 
the variable/parameter that contains the data and the size of the data 
to the Write method.

To use the write method with a simple record (that does not contain a 
Pointer-based type like String or a dynamic array) you can use it this way:

MyStream.Write(MyRecordVar, SizeOf(TMyRecordType));

That will write the contents of your record into the stream.

Regards,
Sven



More information about the fpc-pascal mailing list