How to draw a line at the current date and time.


This example uses the same technique as FAQ 25, but instead of displaying a logo, it draws a line at the current date and time.

The key to this technique is to implement an OnDrawProgress event handler. This event is fired at various stages in the drawing process, and so allows additional graphics to be added at each stage. For example, you may want to add graphics on top of the plot background and allocation shadows, but behind the allocations themselves — in this particular case, you'd draw your graphics when the "Progress" argument is equal to dpShadowsDone. These are the values and meanings of the Progress argument.

TssDrawProgressMeaning
dpBeforeStartBefore any drawing has been done. Can be used as a reset.
dpFrameDoneThe outer frame has been drawn.
dpBackgroundDoneThe background has been drawn, including any alternating colour.
dpLabelsDoneThe resource name and date/time labels have been drawn. This is the earliest point at which the TssResource.PlotRect is valid.
dpShadowsDoneThe allocation shadows have been drawn.
dpAllocationsDoneThe allocations have been drawn.
dpAllDoneAll drawing is finished.

This example draws a blue line at the current date and time.

Screen shot
procedure TForm1.RACDrawProgress(Sender: TObject;
                                 Canvas: TCanvas;
                                 DrawRect: TRect;
                                 Progress: TssDrawProgress);
var
  x: integer;
begin
  // indicate the current time with a vertical line
  if Progress = dpShadowsDone then begin
    x := RAC.DateTimeToX(Now);
    Canvas.Pen.Color := clBlue;
    Canvas.Pen.Width := 2;
    Canvas.MoveTo(x, DrawRect.Top);
    Canvas.LineTo(x, DrawRect.Bottom);
  end;
end;

Note: This event handler can be invoked many times a second while the user is dragging the chart or an allocation. It is important that it completes quickly in order to maintain a responsive user experience.

What People Say

Resource Allocation Chart is one of those rare components that really fires the imagination. It looks great and is extremely flexible. A must for any application that allocates time slots.
Trevor Pegley, Visionhall
More …

No malware No spam
McAfee Site Report
Web of Trust