home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,977 of 2,978   
   Femme Verbeek to Jim Leonard   
   Re: How to iterate through 80-100 proced   
   27 Dec 05 00:10:40   
   
   From: fv@nospam.tcenl.com   
      
   Jim Leonard schreef:   
   > Dr John Stockton wrote:   
   >   
   >>Having defined all routines individually, can you not declare a constant   
   >>array of routine with contents being the list of routines?   
   >   
   >   
   > I think there's no way to avoid this, sadly :-)  I will combine your   
   > method with the method suggested later in the thread of scanning the   
   > source code and generating an include file; I think that's the best way   
   > to automate things.   
   >   
   > However, how to do execute a pointer?  For example:   
   >   
   > var   
   >   p:pointer;   
   >   
   > begin   
   >   p:=@myproc;   
   >   ...???...   
   >   
   > How do I actually "execute" p?  Is there a way to do that in pure Turbo   
   > Pascal 7?  If not, I guess I could always do "asm; call p; end;" but   
   > I'd like to restrict the assembler portions of the source to the actual   
   > tests being performed.   
   >   
   In order to execute it you must make it a function pointer.   
   Note that in the example below the @ symbol should not be used for the   
   function pointer assignment.   
      
   e.g.   
      
   {$F+} {far calling model!}   
      
   type   
      IntFuncType = function (x, y : integer) : integer;   
      proctype=procedure(b:boolean);   
   var   
      IntFuncVar : IntFuncType;   
      
      
   procedure dingus(b:boolean);   
   begin   
      write(b);   
   end;   
   procedure doedingus(jaja:proctype);   
   begin   
      jaja(true);   
   end;   
      
      
   procedure DoSomething(Func : IntFuncType; x, y : integer);   
   begin   
      Writeln(Func(x, y):5);      { call the function parameter }   
   end;   
      
   function AddEm(x, y : integer) : integer;   
   begin   
      AddEm := x + y;   
   end;   
      
   function SubEm(x, y : integer) : integer;   
   begin   
      SubEm := x - y;   
   end;   
      
   begin   
      doedingus(dingus);   
      { Directly: }   
      DoSomething(AddEm, 1, 2);   
      DoSomething(SubEm, 1, 2);   
      
      { Indirectly: }   
      IntFuncVar := AddEm;              { an assignment, not a call }   
      DoSomething(IntFuncVar, 3, 4);    { a call }   
      IntFuncVar := SubEm;              { an assignment, not a call }   
      DoSomething(IntFuncVar, 3, 4);    { a call }   
   end.   
      
   --   
   Femme   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca