First, I still very much am looking for answers to my original post, so this last addition is just for free for someone else!!! I tried my hand at custom drawing and it works, but I think the TMS progress bar is more attractive. If anyone else wants a custom draw example, well, here is one...
(Note: for this one I am storing an integer in the field from 0 to 101 where 101 is marked fully completed and colored blue instead of green. This is a calculated database field where the 101 is stored in OnCalcFields)
procedure TFormMain.gridClassesCellBeforeDraw(Sender: TObject; ACol,
ARow: Integer; ACanvas: TCanvas; var ARect, ATextRect: TRectF; var ADrawText,
ADrawBackGround, AllowDraw: Boolean);
var
iValue : integer;
sText : string;
ProgressRect : TRectF;
W, H : single;
begin
if (ACol = 5) and (ARow > 0) then begin
// We have a progress cell!
iValue := StrToIntDef(gridClasses.Cells[ACol, ARow], 0);
if (iValue < 0) then iValue := 0;
if (iValue > 100) then begin
// Class Mark Completed, Fill it with blue
// ACanvas.Stroke.Color := TAlphaColors.Blue;
ACanvas.Stroke.Color := $FF7B84E1;
ACanvas.Fill.Color := $FF7B84E1;
ACanvas.FillRect(ATextRect, 0, 0, [], 1);
ADrawBackGround := false;
sText := 'Completed';
end else if (iValue = 100) then begin
// Class Completed but Not Marked, Fill Green
ACanvas.Stroke.Color := $FF53E176;
ACanvas.Fill.Color := $FF53E176;
ACanvas.FillRect(ATextRect, 0, 0, [], 1);
ADrawBackGround := false;
sText := '100%';
end else begin
// Not completed, Draw your own progress bar
ACanvas.Stroke.Color := $FFCCCCCC;
ACanvas.Fill.Color := $FFCCCCCC;
ACanvas.FillRect(ATextRect, 0, 0, [], 1);
ACanvas.Stroke.Color := $FF53E176;
ACanvas.Fill.Color := $FF53E176;
ProgressRect.Left := ATextRect.Left;
ProgressRect.Top := ATextRect.Top;
ProgressRect.Bottom := ATextRect.Bottom;
ProgressRect.Right :=
ATextRect.Left +
((ATextRect.Right - ATextRect.Left) * iValue / 100);
ACanvas.FillRect(ProgressRect, 0, 0, [], 1);
ADrawBackground := false;
sText := IntToStr(iValue) + '%';
end;
// We have sText with the contents, draw it centered in the rectangle
W := ACanvas.TextWidth(sText);
// Note, I don't want some lines aligning differently, so standardized centering
H := ACanvas.TextHeight('Ayg');
ACanvas.Fill.Color := $FF000000;
ACanvas.FillText(ATextRect, sText, false, 1.0,
[TFillTextFlag.ftRightToLeft],
TTextAlign.taCenter, TTextAlign.taCenter);
ADrawText := false;
end else begin
ADrawBackground := true;
end;
end;