Recent

Author Topic: I finally found a use for procedural variables  (Read 461 times)

TBMan

  • Sr. Member
  • ****
  • Posts: 275
I finally found a use for procedural variables
« on: September 20, 2025, 06:26:04 pm »
I always wondered why I would need this, but finally something popped up and it was a perfect solution.

I have my basic playing card drawing routines in a unit. In that unit is an "animatecard" procedure that moves a card from one point to another. I'm using page flipping to make it work without flickering. The animatecard procedure needs to update the background screen, which is unique for every game, prior to drawing a card at its new location. Using a procedural variable passed by the calling procedure it enables the animatecard procedure to update properly by calling the passed procedural variable. 

The animatecard routine gets called as
Code: Pascal  [Select][+][-]
  1. animatecard(fromx,fromy,tox,toy,reps,card,@paintscreen);
  2.  

The animatecard uses an unrolled version of brensenham's integer only line algorithm to move the card from the startpoint to the endpoint.


Thaddy

  • Hero Member
  • *****
  • Posts: 18304
  • Here stood a man who saw the Elbe and jumped it.
Re: I finally found a use for procedural variables
« Reply #1 on: September 20, 2025, 06:50:42 pm »
Well, such construct is a precursor to things like interfaces, generics etc, only with old school Pascal:
Code: Pascal  [Select][+][-]
  1. {$mode tp}
  2. type
  3.   Tproc = procedure;
  4.  
  5.   procedure a;
  6.   begin
  7.     writeln('do something');
  8.   end;
  9.  
  10.   procedure b;
  11.   begin
  12.     writeln('do something else');
  13.   end;
  14.  
  15.   procedure c;
  16.   begin
  17.     writeln('and now for something completely different...');
  18.   end;
  19.  
  20. procedure execute(const value:TProc);
  21. begin
  22.   value;
  23. end;
  24.  
  25. begin
  26.   execute(a());
  27.   execute(b());
  28.   execute(c());
  29. end.
 
So why didn't you find a use for it before?
Just curious....

(This is ISO, TP and Delphi compatible. I have used it since at least the late 80's. For objfpc/fpc add the ubiquitous @ )
« Last Edit: September 20, 2025, 09:14:06 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

TBMan

  • Sr. Member
  • ****
  • Posts: 275
Re: I finally found a use for procedural variables
« Reply #2 on: September 20, 2025, 09:51:31 pm »
.
.
.
So why didn't you find a use for it before?
Just curious....

.....

I never really understood the need for it. I'm just a hobbyist and generally don't care if I duplicate code or know the language inside and out. I could also just have the animatecard routine in every card game. It isn't critical, but it is nice to have it available without cutting and pasting the code and learning something new is always good.

 

TinyPortal © 2005-2018