Skip to main content
Table of Contents

Building a project

A freshly dropped TTMSFNCGanttChart already owns an internal default project and is pre-filled with sample data, so you see a working chart at design time. At runtime you normally clear that sample data and build your own project. Tasks are created through the project, not by adding to a raw collection: AddTask creates a top-level (summary) task, AddSubTask nests one task under another, and AddDependentTask creates a task already linked to a predecessor. Wrap bulk changes in BeginUpdate/EndUpdate so the chart recalculates and repaints once instead of after every change.

Build a project with subtasks and dependenciesPascalC++
procedure TForm1.BuildProject;
var
  LAssessment, LDesign, LFiles, LMap, LMockups: TTMSFNCGanttTask;
begin
  TMSFNCGanttChart1.BeginUpdate;
  try
    { Start from an empty project - a freshly dropped chart contains sample data. }
    TMSFNCGanttChart1.Project.Tasks.Clear;

    { Summary tasks group their subtasks; their dates are derived from the children. }
    LAssessment := TMSFNCGanttChart1.Project.AddTask('Assessment', 'First checks before the project can start');

    { A subtask scheduled three working days from a fixed start. }
    LFiles := LAssessment.AddSubTask('Files review', 'Validate the customer checklist.',
      Trunc(Now), 3, gdtWorkDays, whWorkTimeAndDays, 100);

    { AddDependentTask creates the task and links it to its sibling in one call. }
    LMap := LFiles.AddDependentTask('Map site', 'Plan the pages of the site.',
      gtdFinishToStart, 3, gdtWorkDays, 0, gdtSeconds, whWorkTimeAndDays, 20);

    LDesign := TMSFNCGanttChart1.Project.AddTask('Design', 'Visual design of the site');
    LMockups := LDesign.AddSubTask('Mockups', 'Create style mockups.',
      Trunc(Now) + 4, 3, gdtWorkDays, whWorkTimeAndDays, 0);

    { An explicit dependency with a one-working-day delay between two existing tasks. }
    LMockups.TaskDependencies.AddDependency(LMap, gtdFinishToStart, 1, gdtWorkDays);

    { A task with no start date is shown as unscheduled. }
    TMSFNCGanttChart1.Project.AddTask('Unscheduled task', 'No start date set yet.');
  finally
    TMSFNCGanttChart1.EndUpdate;
  end;
end;
void __fastcall TForm1::BuildProject()
{
  TTMSFNCGanttTask *LAssessment, *LDesign, *LFiles, *LMap, *LMockups;

  TMSFNCGanttChart1->BeginUpdate();
  try
  {
    // Start from an empty project - a freshly dropped chart contains sample data.
    TMSFNCGanttChart1->Project->Tasks->Clear();

    // Summary tasks group their subtasks; their dates are derived from the children.
    LAssessment = TMSFNCGanttChart1->Project->AddTask("Assessment", "First checks before the project can start");

    // A subtask scheduled three working days from a fixed start.
    LFiles = LAssessment->AddSubTask("Files review", "Validate the customer checklist.",
      Date(), 3, gdtWorkDays, whWorkTimeAndDays, 100);

    // AddDependentTask creates the task and links it to its sibling in one call.
    LMap = LFiles->AddDependentTask("Map site", "Plan the pages of the site.",
      gtdFinishToStart, 3, gdtWorkDays, 0, gdtSeconds, whWorkTimeAndDays, 20);

    LDesign = TMSFNCGanttChart1->Project->AddTask("Design", "Visual design of the site");
    LMockups = LDesign->AddSubTask("Mockups", "Create style mockups.",
      Date() + 4, 3, gdtWorkDays, whWorkTimeAndDays, 0);

    // An explicit dependency with a one-working-day delay between two existing tasks.
    LMockups->TaskDependencies->AddDependency(LMap, gtdFinishToStart, 1, gdtWorkDays);

    // A task with no start date is shown as unscheduled.
    TMSFNCGanttChart1->Project->AddTask("Unscheduled task", "No start date set yet.");
  }
  __finally
  {
    TMSFNCGanttChart1->EndUpdate();
  }
}
A populated Gantt Chart with summary tasks, subtasks and dependency arrows A populated Gantt Chart with summary tasks, subtasks and dependency arrows

Task creation parameters

AddTask, AddSubTask, and AddDependentTask share the same trailing parameters, so you can set up a task fully in one call:

Parameter Meaning
AName The task caption (Name).
ADescription Long text shown in the description column and editor.
AStartDate Planned start; pass 0 to leave the task unscheduled.
ADurationValue / ADurationType Length and its unit (gdtSeconds, gdtHours, gdtWorkDays).
AWorkTimePolicy Whether the duration skips non-working time.
AProgress Completion percentage, 0–100.
AState A TTMSFNCGanttTaskState to color and tag the task.

A summary task (one with subtasks) derives its own start, end, and progress from its children, so you usually leave its dates unset and only schedule the leaves.

Relative and dependent tasks

Beyond AddDependentTask, the task and project expose helpers that position a new task relative to an existing one without computing dates yourself: AddNextTask, AddNextTaskPrevious, AddNextTaskSameStartDate, and AddNextTaskSameEndDate. To add an explicit link between two tasks that already exist, call TaskDependencies.AddDependency with the predecessor, a dependency type, and an optional delay.

Milestones

A milestone with no duration is an event marker. Create one with AddSubEventMarker, AddNextEventMarker, or AddDependentEventMarker, or set an existing task's IsEventMarker to True. Markers participate in dependencies just like normal tasks.

Putting it together

A single build that uses each technique above — a subtask with explicit parameters, a dependent task, and a milestone marker:

Subtasks, a dependent task, and a milestone togetherPascalC++
procedure TForm1.BuildMixedProject;
var
  LDesign, LMockups, LBuild: TTMSFNCGanttTask;
begin
  TMSFNCGanttChart1.BeginUpdate;
  try
    TMSFNCGanttChart1.Project.Tasks.Clear;

    { Task-creation parameters: name, start, duration, work-time policy, progress. }
    LDesign := TMSFNCGanttChart1.Project.AddTask('Design', 'Visual design');
    LMockups := LDesign.AddSubTask('Mockups', 'High-fidelity mockups',
      Trunc(Now), 3, gdtWorkDays, whWorkTimeAndDays, 100);

    { Relative/dependent task: Build follows Mockups finish-to-start. }
    LBuild := LMockups.AddDependentTask('Build', 'Implementation',
      gtdFinishToStart, 5, gdtWorkDays, 0, gdtSeconds, whWorkTimeAndDays, 40);

    { Milestone: a zero-duration marker after Build. }
    LBuild.AddNextEventMarker('Release', 'Ship it');
  finally
    TMSFNCGanttChart1.EndUpdate;
  end;
end;
void __fastcall TForm1::BuildMixedProject()
{
  TTMSFNCGanttTask *LDesign, *LMockups, *LBuild;

  TMSFNCGanttChart1->BeginUpdate();
  try
  {
    TMSFNCGanttChart1->Project->Tasks->Clear();

    // Task-creation parameters: name, start, duration, work-time policy, progress.
    LDesign = TMSFNCGanttChart1->Project->AddTask("Design", "Visual design");
    LMockups = LDesign->AddSubTask("Mockups", "High-fidelity mockups",
      Date(), 3, gdtWorkDays, whWorkTimeAndDays, 100);

    // Relative/dependent task: Build follows Mockups finish-to-start.
    LBuild = LMockups->AddDependentTask("Build", "Implementation",
      gtdFinishToStart, 5, gdtWorkDays, 0, gdtSeconds, whWorkTimeAndDays, 40);

    // Milestone: a zero-duration marker after Build.
    LBuild->AddNextEventMarker("Release", "Ship it");
  }
  __finally
  {
    TMSFNCGanttChart1->EndUpdate();
  }
}

See also