Recent

Author Topic: Free Pascal function declaration with missing parameter variable type  (Read 2328 times)

Pasqualish

  • Jr. Member
  • **
  • Posts: 68
The documentation for THandleStream.Read shows:

Code: Pascal  [Select][+][-]
  1.  public function THandleStream.Read(
  2.   var Buffer;
  3.   Count: LongInt
  4. ):LongInt; override;

What does it mean when there is no variable type as there is above for "Buffer"?

Edit: I found the answer in the documentation

Quote
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 passed to a function that has also an untyped parameter. If an untyped parameter is used in an assignment, or a value must be assigned to it, a typecast must be used.
« Last Edit: September 18, 2017, 02:32:10 am by Pasqualish »

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Free Pascal function declaration with missing parameter variable type
« Reply #1 on: September 18, 2017, 10:53:19 am »
Note you can also declare a local variable (of any type) as absolute to the buffer parameter in your overridden Read function..
That is missing from the docs?

E.g.:
Code: Pascal  [Select][+][-]
  1. program testvarbuf;
  2. {$mode objfpc}{$H+}
  3. procedure TestMe(var buf);
  4. var
  5.   s:string absolute buf;
  6. begin
  7.   writeln(s);
  8. end;
  9.  
  10. var s:string = 'untyped buffer?';
  11. begin
  12.   Testme(s); // can not pass a literal, needs to be a variable
  13.   Readln;
  14. end.

In the context of a specific stream you can use this for e.g. records.
I don't like untyped, but sometimes it comes in handy.
« Last Edit: September 18, 2017, 01:49:20 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018