What type are parameters without type like in the class TStringStream:
function Read(var Buffer; Count: Longint): Longint; override;
What is the type of Buffer parameter (is it a type of Pointer ?).
I wrote an article about this very topic a few years ago:
Untyped parameters are used in a few situations; the TStream.Read
method you ask about most closely matches with the Move
procedure I wrote about. Here's an excerpt:
procedure Move(const Source; var Dest; Count: Integer);
The
Move
procedure copies data from an arbitrary variable into any other variable. It needs to accept sources and destinations of all types, which means it cannot require any single type. The procedure does not modify the value of the variable passed forSource
, so that parameter’s declaration usesconst
instead ofvar
, which is the more common modifier for untyped parameters.
In the case of TStream.Read
, the source is the stream's contents, so you don't pass that in as a parameter, but the destination is the Buffer
parameter shown in the question. You can pass any variable type you want for that parameter, but that means you need to be careful. It's your job, not the compiler's, to ensure that the contents of the stream really are a valid value for the type of parameter you provide.
Read the rest of my article for more situations where Delphi uses untyped parameters.