home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l044 / 4.ddi / DEMOS.ZIP / PROCVAR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-10-23  |  972 b   |  42 lines

  1.  
  2. { Copyright (c) 1989,90 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 Programmer's Guide.
  8. }
  9.  
  10. type
  11.   IntFuncType = function (x, y : integer) : integer; { No func. identifier }
  12.  
  13. var
  14.   IntFuncVar : IntFuncType;
  15.  
  16. procedure DoSomething(Func : IntFuncType; x, y : integer);
  17. begin
  18.   Writeln(Func(x, y):5);      { call the function parameter }
  19. end;
  20.  
  21. function AddEm(x, y : integer) : integer;
  22. begin
  23.   AddEm := x + y;
  24. end;
  25.  
  26. function SubEm(x, y : integer) : integer;
  27. begin
  28.   SubEm := x - y;
  29. end;
  30.  
  31. begin
  32.   { Directly: }
  33.   DoSomething(AddEm, 1, 2);
  34.   DoSomething(SubEm, 1, 2);
  35.  
  36.   { Indirectly: }
  37.   IntFuncVar := AddEm;              { an assignment, not a call }
  38.   DoSomething(IntFuncVar, 3, 4);    { a call }
  39.   IntFuncVar := SubEm;              { an assignment, not a call }
  40.   DoSomething(IntFuncVar, 3, 4);    { a call }
  41. end.
  42.