home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / turbo5 / procvar.pas < prev    next >
Pascal/Delphi Source File  |  1988-10-09  |  1KB  |  43 lines

  1.  
  2. { Copyright (c) 1988 by Borland International, Inc. }
  3.  
  4. {$F+}
  5. program ProcVar;
  6. { For an extensive discussion of procedural types, variables and
  7.   parameters, refer to Chapter 8 in the Turbo Pascal 5.0 Reference
  8.   Guide (or Chapter 7 in the Turbo Pascal 5.0 Update manual).
  9. }
  10.  
  11. type
  12.   IntFuncType = function (x, y : integer) : integer; { No func. identifier }
  13.  
  14. var
  15.   IntFuncVar : IntFuncType;
  16.  
  17. procedure DoSomething(Func : IntFuncType; x, y : integer);
  18. begin
  19.   Writeln(Func(x, y):5);      { call the function parameter }
  20. end;
  21.  
  22. function AddEm(x, y : integer) : integer;
  23. begin
  24.   AddEm := x + y;
  25. end;
  26.  
  27. function SubEm(x, y : integer) : integer;
  28. begin
  29.   SubEm := x - y;
  30. end;
  31.  
  32. begin
  33.   { Directly: }
  34.   DoSomething(AddEm, 1, 2);
  35.   DoSomething(SubEm, 1, 2);
  36.  
  37.   { Indirectly: }
  38.   IntFuncVar := AddEm;              { an assignment, not a call }
  39.   DoSomething(IntFuncVar, 3, 4);    { a call }
  40.   IntFuncVar := SubEm;              { an assignment, not a call }
  41.   DoSomething(IntFuncVar, 3, 4);    { a call }
  42. end.
  43.