Bayesean Blog - Desktop, Mobile and IOT Developer Blog


Delphi A Professional VCL DBGrid Part Four

Posted on 13th Jun 2019 in Delphi VCL


part4header54.png

The Last in the series Part Four covers the following areas.

  • Progress bar single to multi-color 5 bar
  • Horizontal Stack Bar multi-colors

 Feel free to read part one, part two, part three

Progress bar single to multi-color

The progressbar procedure has the option of selecting up to 5 different colors. The procedure has many default settings which can easily be overridden to create a custom looking progressbar.

The standard settings allows maximum of 5 colors in its settings but can be easily adjusted to the minimum of one color.

The procedure has an overduebreakpoint and various breakpoint positions where the color of the progressbar will change color.

If no changes are added during usage then the defaults are automatically used.

In the procedure there are many adjustable settings that can be made which influence how the bar is visualised at run time. With few changes, a custom styled progress bar can be created.

Usage

Progressdrawcolumncell(Sender,dbgrid1,9,datacol,e,Rect,column,State,1);

Code

 

procedure Progressdrawcolumncell(sender:Tobject;grid:Tdbgrid;

  colpos,datacol,progressvalue: integer;

  Rect:Trect;column:Tcolumn;State: TGridDrawState;

  progressnumber:integer = 5;

  overduebreakpoint:integer = 1;

  breakpoint1:integer = 65;

  breakpoint2:integer = 40;

  breakpoint3:integer = 20;

  backgroundcolor:TColor = clgray;

  overduecolor:Tcolor=clwebFirebrick;

  Color1:Tcolor = clWebLightSkyBlue;

  Color2:Tcolor = clweborange;

  Color3:TColor = clWebGold;

  color4:Tcolor = clWebTomato;

  maxvalue:integer = 100;

  progresspadding:integer = 0;

  isbackground:boolean= false;

  showtext:boolean = true;

  Percentge:string = '%');

 The code for this procedure is many lines and can be found in the full code download.

 

Horizontal Stack Bar multi-colors

This is a stacked bar with up to five different colors. To initiate the colors, the formOncreate event is used to activate the bar. It uses a shape to draw each bar.  Select the color that the shape must take and a stacked bar is formed.

Usage

 

ColorhorizontalBarshape(shape1,clWebLightSkyBlue);

 ColorhorizontalBarshape(shape2,clWebLightSeaGreen);

 ColorhorizontalBarshape(shape3,clweborange);

 ColorhorizontalBarshape(shape4,clWebGold);

 ColorhorizontalBarshape(shape5,clWebTomato);

 Code

 

procedure ColorhorizontalBarshape(shape:Tshape;color:Tcolor);

  begin

  shape.Brush.Color:= color;

  shape.Pen.Style:= psClear;

  end;

 The stack Bar is drawn in the DBgrid onDrawColumncell event. Progress values for each shape must be added. The example uses random numbers to populate the chart, numbers from a Database can easily be incorporated into the chart. The maximum bars that can be added are five and minimum bar requirement is one.

The percentage can be changed from %e to any string item. Be aware that the bar would look best with a $ sign for value but the bar would become crowded if a long string name were used. There is the ability to not show any indicators in the bar.

Usage

HorizontalBardrawcolumncell(sender,dbgrid1,3,datacol,a,b,20,c,d,Rect,column,State,5);

 Code

 

procedure HorizontalBardrawcolumncell(sender:Tobject;grid:Tdbgrid;

  colpos,datacol,progressvalue1,progressvalue2,progressvalue3,progressvalue4,

progressvalue5: integer;

  Rect:Trect;column:Tcolumn;State: TGridDrawState;

  progressnumber:integer = 5; //min 1

  Color1:Tcolor = clWebLightSkyBlue;

  Color2:Tcolor = clWebLightSeaGreen;

  Color3:TColor = clweborange;

  color4:Tcolor = clWebGold;

  color5:Tcolor = clWebTomato;

  maxvalue:integer = 100;

  progresspadding:integer = 0;

  isbackground:boolean= false;

  showtext:boolean = true;

  Percentge:string = '%');

 The lengthy code for this can be viewed in the example download.

 Code Repository

Feel Free to download the code that covers all four parts here

 

Download Code


Randy E      Commented   3 years ago Reply

Hi Good day it not easier to use javascript to create this.

Admin      Replied    Moderator   3 years agoReply


Hi Randy Yes, I agree that Javascript is a good option. Using just CSS would ensure that all browser would always function even if JavaScript was not enabled in the browser.

Add a Comment

9+5

Recent News

Delphi Delimited String to Fields
Delphi A Professional VCL DBGrid Part Four
Delphi A Professional VCL DBGrid Part Three
Delphi A Professional VCL DBGrid Part Two
Delphi A Professional VCL DBGrid Part One
Delphi VCL Buttons in DBGrid
Two Helper Apps for Delphi LibUSB
Delphi Libusb Library Introduction

Categories

Bootstrap 4
Delphi VCL
Delphi FMX
Ajax
Bootstrap 3
CSS
XE4>Delphi > XE4
Delphi < XE4
PHP

Archives

August 2019

Delphi Delimited String to Fields

June 2019

Delphi A Professional VCL DBGrid Part Four

May 2019

Delphi A Professional VCL DBGrid Part Three

April 2019

Delphi A Professional VCL DBGrid Part Two

March 2019

Delphi A Professional VCL DBGrid Part One

November 2018

Delphi VCL Buttons in DBGrid

October 2018

Two Helper Apps for Delphi LibUSB

September 2018

Delphi Libusb Library Introduction

August 2018

Delphi Object directly to a Json string in a REST Client
Delphi using Environment Variables in your App

July 2018

Delphi FMX Leaflet Plotter using OSM Maps

June 2018

C2PAS32 Convertor Application
C to Delphi Open Source Convertors Shootout
Delphi command-line programs with DOSCommand

May 2018

Delphi PDF Embedded viewer with PDF.js

March 2018

Delphi FMX - Changing TCharacter to TCharHelper
Make Your Delphi App POP using Javascript!

January 2018

Delphi FMX Dashboard using Chart.JS
Delphi FMX Form Docking

December 2017

PHP Slim REST Server & Delphi Auth Part 5

November 2017

Delphi FMX REST Client App Part 4

October 2017

Delphi VCL REST Pricing Client App Part 3

September 2017

Delphi REST VCL Client Basic Auth Part 2B

August 2017

Delphi REST Client Part 2A
PHP PDO REST Server Part 1

July 2017

PHP REST Server and Delphi Client Intro

June 2017

Delphi SQLite Encryptor-Decryptor Tool
Updating Applications Manifest using Delphi

May 2017

Create a Visual IP Address Geolocation with PHP

March 2017

PHP Downloader using Countdown timer
PHP File Downloader from a Inbox Selection

February 2017

Javascript Image-File Uploader with ThumbViewer

January 2017

Morris Charts and PHP-PDO

December 2016

CSS to create a functional Toggle Button