Optimisation Hint - Use PolyLine

'

Use PolyLine rather than MoveTo and LineTo

Each call to MoveTo or LineTo results in a GDI system call - a relatively expensive operation. Preparing all the drawing instructions in advance and making a single call to a higher-level drawing function is almost always more efficient.

For example replacing the first block of code below with the second will produce the same results but take an order of magnitude less time to execute:

Slow with MoveTo and LineTo

begin
   MoveTo( 0, F(0) );
   for i:= 1 to 100 do
      LineTo( i, F(i) );
end;

Fast way using PolyLine

var TPA: array of TPoint;
begin
   SetLength( TPA, 101 );

   for i := 0 to 100 do
      with TPA[i] do
      begin
         X := i;
         Y := F(i);
      end;

   Polyline( TPA );
end;
This hint was provided by Paul McCue. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available here.
Google
Web www.Delphi-Central.com
Delphi Central - Delphi Programming Tutorials, Hints and Tips