Skip to main content

How to Create Tasks in Gantt View in Code

  • 2 minutes to read

The ExpressScheduler provides the following API that allows you to build a task plan in Gantt View programmatically:

The following example demonstrates how to create tasks in Gantt View using this API:

// ...
var
  I: Integer;
  APreEvent, AEvent: TcxSchedulerEvent;
begin
  APreEvent := nil;
  for I := 1 to 10 do
  begin
    AEvent := Scheduler.Storage.createEvent;
    with AEvent do
    begin
      Caption := IntToStr(I);
      Start := Trunc(Date * 24) / 24;
      Duration := 1 / 24 + Trunc(RandomRange(1, 5)) / 24;
      TaskComplete := RandomRange(0, 100);
      Post;
      TaskLinks.Add(APreEvent, TcxSchedulerEventRelation(RandomRange(0, 3)));
    end;
    APreEvent := AEvent;
  end;
end;

The following image shows the code execution result:

The following image shows the task completion percentage (if the scheduler’s ViewGantt.EventsStyle property is esProgress):

See Also