How to limit the dragged/stretched allocations to a fixed chart time span.


If you are limiting the chart to a particular date/time range, and are allowing allocations to be dragged and/or stretched, you'll also want to make sure the allocations can't be dragged or stretched outside the allowed range.

procedure TForm1.RACAllocationDrag(Sender: TObject;
                             Resource: TssResource;
                             Allocation: TssResourceAllocation;
                             var StartDateTime,
                                 EndDateTime: TDateTime,
                             var AllowDrag: Boolean);
var
  Duration: TDateTime;
begin
  Duration := EndDateTime - StartDateTime;
  // prevent allocations being dragged outside the allowed chart range
  // FMinDate should be a TDateTime holding the earliest allowed date/time
  // FMaxDate should be a TDateTime holding the latest allowed date/time
  if StartDateTime < FMinDate then begin
    StartDateTime := FMinDate;
    EndDateTime := FMinDate + Duration;
  end else if EndDateTime > FMaxDate then begin
    StartDateTime := FMaxDate - Duration;
    EndDateTime := FMaxDate;
  end;
end;

procedure TForm1.RACAllocationStretch(Sender: TObject;
                             Resource: TssResource;
                             Allocation: TssResourceAllocation;
                             var StartDateTime,
                                 EndDateTime: TDateTime,
                             var AllowDrag: Boolean);
begin
  // prevent allocations being stretched outside the allowed chart range
  // FMinDate should be a TDateTime holding the earliest allowed date/time
  // FMaxDate should be a TDateTime holding the latest allowed date/time
  if StartDateTime < FMinDate then
    StartDateTime := FMinDate
  else if EndDateTime > FMaxDate then
    EndDateTime := FMaxDate;
end;

Note: These event handlers can be invoked many times a second while the user is dragging or re-sizing an allocation. It is important that they complete quickly in order to maintain a responsive user experience.

What People Say

Great product and great service even before we bought.
Marco Napoli, hotel SalesPro
More …

No malware No spam
McAfee Site Report
Web of Trust