How to Use TAdvProgressBar in Your Delphi ProjectsTAdvProgressBar is a versatile visual component from TMS Software that enhances user interfaces in Delphi applications by providing a modern, feature-rich progress indicator. Compared with Delphi’s standard TProgressBar, TAdvProgressBar offers more customization (colors, gradients, shapes), additional modes (marquee, animation), text display options, and event hooks that make it suitable for both simple progress reporting and polished, professional UI elements.
What you need before starting
- A recent version of Delphi (XE2 and later generally supported; check your TMS bundle for exact compatibility).
- TMS Component Pack (or the specific TMS control package that contains TAdvProgressBar) installed and properly registered in the Delphi IDE.
- Basic familiarity with Delphi forms, components, properties, and events.
Adding TAdvProgressBar to your form
- Open your project in the Delphi IDE.
- From the Tool Palette find TAdvProgressBar (usually under the TMS pack or TAdvControls category).
- Drag and drop TAdvProgressBar onto your form or create it at runtime:
uses AdvProgressBar; // or the appropriate unit per your TMS version procedure TForm1.FormCreate(Sender: TObject); begin AdvProgressBar1 := TAdvProgressBar.Create(Self); AdvProgressBar1.Parent := Self; AdvProgressBar1.Left := 16; AdvProgressBar1.Top := 16; AdvProgressBar1.Width := 300; AdvProgressBar1.Height := 24; end;
Basic properties and how to use them
- Max and Min: Set the progress range. Default is typically Min = 0, Max = 100.
Example:AdvProgressBar1.Min := 0; AdvProgressBar1.Max := 200; AdvProgressBar1.Position := 50;
- Position: Current value of the progress. Update this to reflect task progress.
- Orientation: Horizontal or Vertical.
- Smooth: Enables smooth rendering between values instead of stepped updates.
- BarColor / BarColorTo: Use for solid colors or gradients.
- ShowText / Text: Toggles and sets text shown inside the bar.
- MarqueeMode: For indeterminate progress, show animated marquee.
- Steps: If you prefer stepping behavior, set Step and use StepIt to increment.
Displaying progress during long tasks
Directly updating UI from long-running operations blocks the VCL and prevents the progress bar from repainting. Use one of these approaches:
- Use Application.ProcessMessages sparingly:
for i := 0 to 100 do begin // do work AdvProgressBar1.Position := i; Application.ProcessMessages; end;
- Use a background thread (TTask or TThread) and synchronize updates to the UI:
TTask.Run( procedure var i: Integer; begin for i := 0 to 100 do begin // simulate work Sleep(50); TThread.Synchronize(nil, procedure begin AdvProgressBar1.Position := i; end); end; end);
- Use events (OnProgress) from asynchronous operations if available.
Customizing look and feel
- Gradients and multiple colors:
AdvProgressBar1.BarColor := clBlue; AdvProgressBar1.BarColorTo := clSkyBlue; // gradient end AdvProgressBar1.Gradient := True;
- Rounded corners, border and flat styles are available via properties like RoundCorner and Bevel.
- Text alignment, font, and format:
AdvProgressBar1.ShowText := True; AdvProgressBar1.Text := 'Loading... %d%%'; AdvProgressBar1.TextAlign := taCenter;
Note: Use the Position value to dynamically format text in code.
Using Marquee and Indeterminate modes
For operations where progress cannot be measured:
AdvProgressBar1.MarqueeMode := True; AdvProgressBar1.MarqueeSpeed := 50; // lower = faster
This displays a moving block or animated effect indicating activity without exact percentage.
Animation and advanced features
- Animated transitions: set Smooth to True and adjust AnimationSpeed for visually pleasing changes.
- Segmented bars: Use Steps property and custom drawing to create segmented/striped progress visuals.
- Events: OnChange, OnClick, OnGetText allow you to react to user interaction and modify display dynamically.
Accessibility and RTL support
TAdvProgressBar supports right-to-left layouts and can be made accessible by setting appropriate captions and ensuring color contrast for screen readers.
Example: File copy simulation with TAdvProgressBar
procedure TForm1.ButtonStartClick(Sender: TObject); begin AdvProgressBar1.Min := 0; AdvProgressBar1.Max := 100; AdvProgressBar1.Position := 0; TTask.Run( procedure var i: Integer; begin for i := 1 to 100 do begin Sleep(40); // simulate work TThread.Queue(nil, procedure begin AdvProgressBar1.Position := i; AdvProgressBar1.Text := Format('Copying files... %d%%', [i]); end); end; end); end;
Tips and common pitfalls
- Avoid heavy UI updates on the main thread—use background threads and synchronize only UI changes.
- Remember to set Min/Max appropriately if you change units (bytes, items, steps).
- When using gradients or custom drawing, test on different DPI settings to ensure visuals scale properly.
- If the progress seems jerky, increase Smooth or adjust AnimationSpeed.
Conclusion
TAdvProgressBar gives Delphi applications a flexible, modern progress indicator with many customization and behavior options beyond the standard VCL control. Use background tasks for long operations, leverage marquee for indeterminate tasks, and tweak visual properties to match your app’s design.
Leave a Reply