TPSProgressMeter component

This is a progress meter. It is based on a component I downloaded off the www.torry.ru site. The original component was called GnouMeter. It was a meter which can display an integer or a float value (Single). Just like a progress bar or a gauge, all you had to do was to define the Minimum and maximum values as well as the actual value.

The following is from designer's read me.txt file for that component.

****************************************************************** ********************

THIS COMPONENT IS ENTIRELY FREEWARE and this is my modest contribution to the world of Delphi.

If you are interested by this component you can contact me to the following address : jhersant@post4.tele.dk

Jérôme Hersant jhersant@post4.tele.dk

****************************************************************** *********************

I have changed some of his code and added a couple of new properties. In my component it will only take a Integer number. My Contribution is the same. The component is FREEWARE. I have supplied the code to try and help others in their quest for programming in a perfect environment. When you do add code try to add comments that help other to understand what you have done. If you don't understand what I have done have no hesitation in emailing me at address shown below with your questions.

If you change my code or add to it please send me a copy at the following address: peter.cook@qr.com.au.


Properties
Methods
Events
Variables

Copyright © 2000 by ... PatSoft


Properties

property BackColor : TColor

This is the background color of the component. You would normally set this component color at design time. It is possible to set it to any color you desire, except black. If you set it to black the floodfill routines will not work and you not be able to see the fonts.

Possible Values - Any color in the color palette.

Default Value - clSilver.


property BarColor : TColor

This is the property to set the color of the bar that is in the middle of the component. The color can be any color you like.

Possible Values - Any color in the pallette

Default Value - clNavy.


property BarWidth : Word

This is the property for the width of the bar that is displayed in the middle of the component. The measurement is in pixels

Possible Values - Equal to or greater than 5

Default Value - 15


property BottomOffset : Word

This is the property to hold the distance in pixels that the bar is from the bottom of the component.

Possible Values - any number.

Default Value - 20.


property Caption : String

This property holds a string that will be shown on the progress meter. This is the text written at the very top of the meter. If you do not enter a caption the value (Progress Value) written below the caption will move upwards.

Possible Value - Any string.

Default Value - Name of component


property DecimalPlaces : Byte

This holds the number of decimal places that can be displayed. At present the progress value has be a integer value so this property should be left with the default. I will probably change the progress value to real numbers in a future release of the component.

Possible Value - Any number

Default Value - 0.


property HasOutline : Boolean

This field will tell the component wether to draw an outline or not. If the property is changed to false the outline is still drawn but the color of the outline is the same as the component background and so it looks like it has disappeared.

Possible Values - True or False.

Default Value - True.


property Height : Integer

This the height of the component.

Possible Values - greater than 0

Default Value - 300.


property IncrementColor : TColor

This is the color of the small increment marks shown on the right hand side of the bar. The best color I have found is black but you may want to change them.

Possible Values - Any color the palette

Default Value - clBlack.


property IncrementSpacing : Integer

This property is the value between each increment. Example - If left at the defaults the increments would be drawn at 10, 20, 30, 40, 50 etc. If the increment was change to 25 then they would be drawn at 25,50, 75. If the maximum value is changed to a larger number than I suggest you increase the increment spacing accordingly.

Possible Values - Any number greater than or equal to 1

Default Value - 10.


property MarkerColor : TColor

This is the color of the marker on the left hand side of the bar. It is best left black but I have added a property so you can change it if you wish to.

Possible Values - Any color the palette

Default Value - clBlack.


property MaxValue : Longint

This is the property to hold the maximum value to be shown on the bar. It can be any number you like but make sure it is greater that the minimum value. It can be negative value.

Possible Values - Any Number. It must be greater than the minimum value.

Default is 100.


property MinValue : Longint

This is the property to hold the minimum value to be shown on the bar. It can be any number you like but make sure it is less than the maximum value. It can be a negative value.

Possible Values - Any Number. It must be less than the maximum value.

Default is 0.


property ProgressValue : Longint

This property holds the current value of the progress meter.

Possible Values - In the range between MinValue and MaxValue.

Default is 0.


property ShowIncrementText : Boolean

This property holds the boolean value that determines if the text is drawn beside each increments on the progress meter. If it is true the increments are drawn. The increments do not need to be shown for the text to be drawn. They are independent of each other.

Possible Values - True or False

Default Value - True


property ShowIncrements : Boolean

This property holds the boolean value that determines if the increments are drawn on the progress meter. If it is true the increments are drawn.

Possible Values - True or False

Default Value - True


property ShowMarker : Boolean

This property holds the boolean value that determines if the progress marker is drawn on the left side of the bar on the progress meter. If it is true the marker is drawn.

Possible Values - True or False

Default Value - True .


property TopOffset : Word

This is the property to hold the distance in pixels that the bar is from the bottom of the text at the top of the component.

Possible Values - any number.

Default Value - 20.


property UnitName : String

This property holds the string name of the units. If this property has something entered it is appended to the increment text when the increment text is displayed. It is also appended to the number shown above the top of the bar on the progress meter.

Possible values - Any text.

Default Value - ""


property Width : Integer

This the width of the component.

Possible Values - greater than 0

Default Value - 120.



Methods

procedure CaptionTextChanged(Var Message : TMessage)

This procedure is used to trigger a repaint of the component when you change the caption text. This is done by monitoring the incoming windows messages and when a CM_TEXTCHANGED message is received the component is put into an invalid state. When the component is in a invalid state it repaints it's self.

Parameters taken - Message of Type TMessage

Returns - NIL.


constructor Create(AOwner: TComponent); override

Creates the component. See code for further info.

Parameters taken - AOwner of Type TComponent

Returns - NIL.


destructor Destroy; override

Destroys the component. See code for more information

Parameters taken - NIL

Returns - NIL.


procedure DrawBasicShape

This procedure draws the basic outline of the component. See the code for more info.

Parameters taken - NIL

Returns - NIL.


procedure DrawIncrementText

This procedure draws the increment text on the component. See the code for more info.

Parameters taken - NIL

Returns - NIL.


procedure DrawIncrements

This procedure draws the increment lines on the component. See the code for more info.

Parameters taken - NIL

Returns - NIL.


procedure DrawMarker

This procedure draws the marker on the component. See the code for more info.

Parameters taken - NIL

Returns - NIL.


procedure DrawMaxValue

This procedure draws the MaxValue as a string on the component. See the code for more info.

Parameters taken - NIL

Returns - NIL.


procedure DrawMeterBar

This procedure draws the actual meter bar on the component. The length of the bar drawn is determined by the current Progress value. See the code for more info.

Parameters taken - NIL

Returns - NIL.


procedure DrawMinValue

This procedure draws the MinValue as a string on the component. See the code for more info.

Parameters taken - NIL

Returns - NIL.


procedure DrawTopText

This procedure draws the text at the top of the component. See the code for more info.

Parameters taken - NIL

Returns - NIL.


procedure FlipBuffers

This procedure swaps the temporary canvas (Bitmap) that the component has been painted on for the component's own canvas.

Parameters taken - NIL

Returns - NIL.


procedure Loaded; override


procedure Paint; override

This procedure brings all the procedures that draw the parts of the component into a single procedure. See the code for more info.

Parameters taken - NIL

Returns - NIL.


function ValueToPixels(Value : LongInt) : Integer

This one of the original pieces of code. I am not sure how it works but it works well. Study it and then you can tell me how it works.

Parameters taken - Value of Type LongInt

Returns - Integer.


procedure WMSize(var Message: TWMSize)

This procedure is used to invalidate the component when it's size changes. It uses the WM_SIZE message from the windows message system to signal that the size has changed. See the code for more info.

Parameters taken - Message of the Type TWMSize

Returns - NIL



Events

event OnClick

See the Delphi help file for more information on this event. They are all inherited. I have not included any special event handling in the component.


event OnDblClick

See the Delphi help file for more information on this event. They are all inherited. I have not included any special event handling in the component.


event OnDragDrop(DragObject: TObject; X, Y: Integer)

See the Delphi help file for more information on this event. They are all inherited. I have not included any special event handling in the component.


event OnMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer)

See the Delphi help file for more information on this event. They are all inherited. I have not included any special event handling in the component.


event OnMouseMove(Shift: TShiftState; X, Y: Integer)

See the Delphi help file for more information on this event. They are all inherited. I have not included any special event handling in the component.


event OnMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer)

See the Delphi help file for more information on this event. They are all inherited. I have not included any special event handling in the component.



Variables

variable BackBuffer : TBitmap

This is the buffer that the component will be drawn on first and then swapped to the canvas of the component. All the painting is done in the backbuffer. By using a backbuffer to do the drawing to and then swapping the canvas in one move it stops the component from flickering between each redraw. IT doesn't stop all the flickering but it does reduce it significantly.


variable DisplayText : String

The DisplayText variable is used to hold a temperary string before it is displayed on the screen. Again this could have been a local variable but it was made global.


variable DrawStyle : Integer

This variable holds a value that is used in the DrawText procedures. It is global but could of well been local to several procedures instead


variable LeftMeter : Word

This holds the location of the left side of the bar.

variable TextDisplayHeight : Word

This variable holds the height of the DisplayText.


variable TextDisplayRect : TRect

This variable holds the rectangle that the DisplayText will be displayed in.