How to add extra columns after the resource name.

This is a more specific example of adding custom graphics (FAQ 25.)

This example adds two columns. Add integer fields to the form for FTextWidth, FCol1X, FLine1X, FCol2X and FLine2X.

Screen shot
procedure TForm1.RACAdjustPlotRect(Sender: TObject;
                                   Canvas: TCanvas;
                                   var PlotRect: TRect);
  i, w, mw, sw: integer;
  mw := 0;
  for i := 0 to RAC.Count - 1 do begin
    w := Canvas.TextWidth(RAC.Resources[i].Name);
    if w > mw then
      mw := w;

  // allow room for our data and lines
  sw := Canvas.TextWidth(' ');
  FTextWidth := Canvas.TextWidth('12.34');

  // must add to existing PlotRect.left - as when
  // printing, PlotRect may already contain print area
  PlotRect.Left := PlotRect.Left + mw + FTextWidth * 2 + sw * 6;

  // calculate column coordinates
  FCol2X := PlotRect.Left - FTextWidth - sw;
  FLine2X := FCol2X - sw;
  FCol1X := FLine2X - FTextWidth - sw;
  FLine1X := FCol1X - sw;

procedure TForm1.RACOwnerDrawResourceName(Sender: TObject;
                                          Resource: TssResource;
                                          Canvas: TCanvas;
                                          Rct: TRect);
  y: integer;
  str: string;
  with Canvas do begin
    // display resource names plus addition column data
    y := (rct.Bottom + rct.Top - TextHeight('Hg')) div 2;
    TextOut(rct.Left + 2, y, Resource.Name);
    str := Format('%4.2f', [V1]); // first column
    TextOut(FCol1X + FTextWidth - TextWidth(str), y, str);
    str := Format('%4.2f', [V2]); // second column
    TextOut(FCol2X + FTextWidth - TextWidth(str), y, str);

procedure TForm1.RACDrawProgress(Sender: TObject;
                                 Canvas: TCanvas;
                                 DrawRect: TRect;
                                 Progress: TssDrawProgress);
  if Progress = dpBackgroundDone then
    // draw column background colours
    with RAC, Canvas do begin
      with Pen do begin
        Color := clBlack;
        Style := psSolid;
        Width := 1;
      Brush.Color := $B8E4CE;
      Brush.Style := bsSolid;
      Rectangle(FLine1X, PlotRect.Top,
                FLine2X+1, PlotRect.Bottom);
      Brush.Color := $E6E2B7;
      Rectangle(FLine2X, PlotRect.Top,
                PlotRect.Left+1, PlotRect.Bottom);
What People Say

... The conclusion cannot be an other one than to state that if you are looking for a planning component you have to get the RAC. For your future planning business it is simply a must.
H. de Boer, Staaf Automatisering (see the full case study)
More …

No malware No spam
McAfee Site Report
Web of Trust