1. Home
  2. Computing & Technology
  3. Delphi Programming

Graphical Progress Bar for Delphi applications - Partial / Continuous Move
Display a continuous bar by "moving" a graphical object

By Zarko Gajic, About.com

When your application performs a time-consuming operation, you can use a progress bar, the TProgressBar Delphi control, to show how much of the task is completed.

When you do not know how many steps are needed for a progress bar - you might want to display a continuous bar - or a moving graphical object. The UpdateImageProgress takes a reference to a TImage control displaying a picture. By calling the procedure from inside, for example, a timer event (TTimer control), a graphical progress effect is achieved.

The UpdateImageProgress shifts the image to the right - using the boundaries of the image - thus creating a continuous progress bar.

//"moves" image to the right in "step" steps
procedure UpdateImageProgress(const img : TImage) ;
const
  step = 4;
var
  b : TBitmap;
begin
  with img.Picture.Bitmap do
  begin
    b := TBitmap.Create;
    try
      b.Width := Width;
      b.Height := Height;
      BitBlt(b.Canvas.Handle, step, 0, Width-step, Height, Canvas.Handle, 0, 0, SRCCOPY) ;
      BitBlt(b.Canvas.Handle, 0, 0, step, Height, Canvas.Handle, Width-step, 0, SRCCOPY) ;
      Assign(b) ;
    finally
      FreeAndNil(b) ;
    end;
  end;
end;
UpdateImageProgress shifts the trailing "step" part of the bitmap to the front, moving the rest along.

Delphi tips navigator:
» Get the Control Under the Mouse in a Delphi application
« Display an Error Message for an OS Error Code using Delphi

More Delphi Programming Quick Tips
D O W N L O A D

Source Code

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2008 Tips
  7. Graphical Progress Bar for Delphi applications - Partial / Continuous Move

©2009 About.com, a part of The New York Times Company.

All rights reserved.