Board index » delphi » How to transfer a function/procedure as a parameter to another func/proc ?

How to transfer a function/procedure as a parameter to another func/proc ?

I heard it's possible, but couldn't figure it out from the BP help.
I would appreciate a proper, detailed explanation.

Thanks in advance,

Eytan.

 

Re:How to transfer a function/procedure as a parameter to another func/proc ?


In article <3477942d.2948...@news.ibm.net.il>,

Quote
The Magician <ey...@mofet.macam98.ac.il> wrote:

:I heard it's possible, but couldn't figure it out from the BP help.

Although this item mostly concerns another question, take a look at
the "type TPixelProc" and the way it is used in the main program by
"testpixel".

 126643 Nov 14 1997 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

122. *****
 Q: What is the code for a fast 256-color PutPixel Routine?

 A: This is a question that is far beyond my own capabilities. The
solution documented and stored here comes from a net friend Scott
Earnest. The material below is edited from correspondence between Dr
John Stockton and Scott. The outcome seems to be instant fast, at
least on my 133MHz Pentium. A warning. Don't try to run this in a
windowed dosbox. The ppix2 routine runs a little faster of the two.

Scott and John exchanged: "Of course, one thing to keep in mind is
that in efficient graphics programming, the single pixel is usually
the most avoided creature, since much more time is used entering and
leaving the procedure than executing the code within the procedure.
For this reason, you'll find that speed-optimized code for drawing
lines, circles, boxes, etc., will use an inline putpixel or inline
code to greatly enhance efficiency."

"The only real problem [in the 256-color PutPixel routines] is
context. The above putpixel functions using Mem[] are not relevant
to the usual BGI modes." Timo's addition. That's why the video
setmode procedure is included. For more on video modes see
ftp://garbo.uwasa.fi/pc/programming/inter55a.zip.

Further comments from Timo. As a sideline note the interesting way
declare a type (TPixelProc) for the procedures to be tested.
Although not necessary, it makes a good shortcut in writing the
source code for the testing the various alternatives of a procedure.

  program testpix;

  {
   Speed comparison for two functionally equivalent putpixel routines
   in mode 13h (320x200x256c).  Speed difference will be most obvious
   if compiled and run under Turbo Profiler.

   (Compiled with range/overflow checking disabled, stack checking
   enabled, debug information included.)
  }

  {$F+} {Require FAR calls}
  uses Dos;

  {$IFNDEF VER70} const SegA000 : word = $A000; {$ENDIF}

  type TPixelProc = procedure (xpos, ypos : word; attribute : byte);

  procedure setmode (mode : word);
  var r : registers;
  begin
    fillchar (r, sizeof(r), 0);
    r.ax := mode;
    intr ($10, r);
  end;

  procedure ppix1 (xpos, ypos : word; attribute : byte);
  begin
    mem[SegA000:xpos+(ypos shl 6)+(ypos shl 8)] := attribute;
  end;

  procedure ppix2 (xpos, ypos : word; attribute : byte);
  begin
    mem[SegA000: (((ypos shl 2)+ypos) shl 6) + xpos] := attribute;
  end;

  procedure testpixel (pixelproc : TPixelProc);
  var
    x, y : word;
    c : byte;
  begin
    setmode ($13);
    for y := 0 to 199 do
      begin
        c := y;
        for x := 0 to 319 do
          begin
            pixelproc (x,y,c);
            c := succ(c) mod 256;
          end;
      end;
    readln;
    setmode ($03);
  end;

  begin
    testpixel (ppix1);
    testpixel (ppix2);
  end.
--------------------------------------------------------------------

   All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland

Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.

Other Threads