Recent

Author Topic: questions concerning procedural types  (Read 567 times)

anonymousstranger

  • New Member
  • *
  • Posts: 49
questions concerning procedural types
« on: January 17, 2021, 02:54:42 am »
1) Given:

Code: Pascal  [Select][+][-]
  1. Type
  2.   TOneArgCcall = Procedure (Var X : integer);
  3.  
  4. var
  5.   proc : TOneArgCcall;  
  6.  
  7. Procedure printit (Var X : Integer);  
  8.  
  9. begin  
  10.   WriteLn (x);  
  11. end;
  12.  
  13. begin  
  14.   Proc := @printit;  
  15. end.
  16.  

How does one pass a value into printit through proc? I'm kind of fuzzy on how this works.

2)Say you have a procedural type that references a procedure/function in a library. does the procedural type also require the "external" tag?

« Last Edit: January 17, 2021, 03:05:41 am by anonymousstranger »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: questions concerning procedural types
« Reply #1 on: January 17, 2021, 03:22:35 am »
Since you pass variable x by reference (var), you have to write:
Code: Pascal  [Select][+][-]
  1. var i: Integer;
  2. begin
  3.  
  4.   Proc := @printit;
  5.  
  6.   i:=5;
  7.   Proc(i);
  8. end;
i can be global variable as well.

Don't know about external keyword.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

anonymousstranger

  • New Member
  • *
  • Posts: 49
Re: questions concerning procedural types
« Reply #2 on: January 17, 2021, 05:09:13 am »
cool  :D thanks.

 

TinyPortal © 2005-2018