Wiliam Cardoso
Wiliam Cardoso

Reputation: 444

Delphi marquee progress bar

I've got a query running in a separate thread which takes a while to process, as the users currently has no way of knowing something is being done in the background I wanted to create a progress bar like the third progress bar on this image:

enter image description here

I've looked at other questions/answers and it looks like a marquee progress bar is what I'm after, I've tried setting my progress bar as marquee but it doesn't do anything. The progress bar properties are as follows:

MarqueeInterval = 10
Max = 100
Min = 50
Orientation = pbHorizontal
Position = 50
Smooth = True
State = pbsNormal
Step = 10
Style = pbstMarquee

Is there something I'm doing wrong or need to change?

My startup code is as follows:

procedure TFormMain.SetupForm;
begin
  // Connect to the database
  ConnectToDatabase;

  // Initially hide combo box
  ShowHideComboBox(False);

  ListViewDataType.Columns[0].Width := -1;

  UsingOwnTemplate := False;

  // Initial page is the welcome page
  PageControl.ActivePage := TabWelcome;
end;

procedure TFormMain.ConnectToDatabase;
var
  FullPath : String;
  CompanyName: String;
begin
  // Create the database connection
  DBConnection := TFDConnection.Create(nil);

  // Get the folder path
  FullPath := GetCurrentDir;

  DatabasePath := FullPath;

  // Setup the database connection
  with DBConnection do begin
    DriverName := 'MSAcc';
    Params.Add(Format('Database=%s', [DatabasePath]));
    Params.Add('StringFormat=UNICODE');
    Connected := True;
  end;
end;

Upvotes: 3

Views: 4316

Answers (2)

Fabrizio
Fabrizio

Reputation: 8043

Place a TProgressBar and set its Style property to pbstMarquee. It should be all, if it doesn't work, make sure that:

  1. The main thread is not blocked (Is the query really executed in another thread or is there any other reason why the main thread could be blocked?)

  2. The project is compiled with the "Enable runtime themes" option enabled (Otherwise, pbstMarquee will not work) enable runtime themes option

Upvotes: 7

Andreas Rejbrand
Andreas Rejbrand

Reputation: 108929

Just drop a TProgressBar on your form and use the Object Inspector to set the Style property to pbstMarquee. That's all!

Screenshot of progress bar

Upvotes: 3

Related Questions