Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7877911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:30:46+00:00 2026-06-03T03:30:46+00:00

FPercentDone was 0 , was assigning it’s value in the wrong place. Adding UpdatePercent

  • 0

FPercentDone was 0, was assigning it’s value in the wrong place. Adding UpdatePercent procedure and calling it when a value changes fixes it and everything gets drawn.

Dumb mistake, sorry for wasting your time.


First of all, this is my first attempt at writing a component of any kind. Properties, methods etc. were an easy part, however I have hit a wall with drawing to the canvas. I am sure this is some rookie mistake, but I simply don’t see it. I have stared at the TGauge included with delphi because I am trying something similar but simpler, it is still just a horizontal bar. I am failing at making it draw the progress at run time, that is the weirdest part, for me anyway, that I can see it working at design time but not when I run it… I do get the background coloring right at least, but no progress bar.

Without any code pasting, since it is similar to TGauge anyway. I have two TBitmap's, one for background the other for the progress bar itself, I fill one with background color, draw that to the component canvas, if there are borders offset the origin of the second one and decrease its rectangle, paint it with the progress color and draw that to the canvas… It seemed this simple to me, but what am I doing wrong?

Relevant code:

type
  TCustomGaugeComp = class(TGraphicControl)
  private
    FMaxValue, FMinValue, FCurValue: DWord;
    FFillBackColor, FFillForeColor: TColor;
    FPercentDone: Real;
    FBorderStyle: TBorderStyle;
    FBorderWidth: Integer;
    procedure SetMaxValue(Value: DWord);
    procedure SetMinValue(Value: DWord);
    procedure SetProgress(Value: DWord);
    procedure SetFillBackColor(Value: TColor);
    procedure SetFillForeColor(Value: TColor);
    procedure SetBorderStyle(Value: TBorderStyle);
    function GetPercentDone: String;
    procedure SetBorderWidth(Value: integer);
  protected
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Align;
    property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
    property BorderWidth: Integer read FBorderWidth write SetBorderWidth default 1;
    property Constraints;
    property Enabled;
    property Font;
    property FillForeColor: TColor read FFillForeColor write SetFillForeColor default clBlack;
    property FillBackColor: TColor read FFillBackColor write SetFillBackColor default clWhite;
    property MinValue: DWord read FMinValue write SetMinValue default 0;
    property MaxValue: DWord read FMaxValue write SetMaxValue default 100;
    property Progress: DWord read FCurValue write SetProgress default 0;
    property PercentDone: String read GetPercentDone;
    property Visible;
  end;


procedure TCustomGaugeComp.Paint;
var
  Background, Progress: TBitMap;
begin
  with Canvas do
  begin
    Background := TBitMap.Create;
    try
      Background.Height := Height;
      Background.Width := Width;
      Background.Canvas.Brush.Color := FFillBackColor;
      Background.Canvas.Brush.Style := bsSolid;
      Background.Canvas.FillRect(ClientRect);
      Progress := TBitMap.Create;
      try
        Progress.Height := Height;
        Progress.Width := Width;
        if FBorderStyle = bsSingle then
        begin
          Progress.Height := Progress.Height - BorderWidth*2;
          Progress.Width := Progress.Width - BorderWidth*2;
        end;
        Progress.Width := trunc(Progress.Width*FPercentDone/100);
        Progress.Canvas.Brush.Color := FFillForeColor;
        Progress.Canvas.FillRect(Rect(0,0,Progress.Width,Progress.Height));
        Background.Canvas.Draw(BorderWidth,BorderWidth,Progress);
      finally
        Progress.Free;
      end;
      Draw(0,0,Background);
    finally
      Background.Free;
    end;
  end;
end;

RePaint (or Refresh) is called whenever a value changes: min/max/position/borderwidth.

In fact it is not acting perfectly at design time either, progress is drawn, at times, sometimes not drawn at all until I just OPEN the Object Inspector, just go with my mouse there… TGauge uses CopyMode excessively, I just started this and I do not really understand CopyMode values yet or its proper use, so copy-pasting and tweaking the code just will not do.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:30:47+00:00Added an answer on June 3, 2026 at 3:30 am

    FPercentDone was 0, was assigning it’s value in the wrong place. Adding UpdatePercent procedure and calling it when a value changes fixes it and everything gets drawn.

    Dumb mistake, sorry for wasting your time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having the tree with all my task which gets all the data
I'm trying to animate object. I use keyframe animation: I have two vertex buffers
I need to download a queue of images. I created my operations first, then
Let's say I created an object O on the thread T. How can I
For a while now, I've been using web services regardless of the purpose with
I know C/C++/C#/ActionScript/PHP and have worked in all of them. As per my Knowledge
I am having issues where I am trying to animate an element. I have
I have the following 2 lines of code: Dim node As XmlNode = xDoc.SelectSingleNode(//response/agentStatusList/agentStatus/protectableVolumes/protectableVolume/metrics/lastWriteTime)
My JsonArray is [{ Id: null, Name: One New task, StartDate: 2010-02-03T05:30:00, EndDate: 2010-02-04T05:30:00,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.