Skip to main content
Table of Contents

End-to-end example

Real screens combine several features at once. The following flow builds a dependent task chain, colors it by state, sets up a weekly/daily timeline, filters down to unfinished work, and exports the filtered view to PDF — exercising task building, states, the timeline, filtering, and export together in one routine.

Build, state-color, filter and export a project end to endPascalC++
procedure TForm1.BuildFilterAndExport;
var
  LActive, LDone: TTMSFNCGanttTaskState;
  LBuild, LTest: TTMSFNCGanttTask;
begin
  TMSFNCGanttChart1.BeginUpdate;
  try
    TMSFNCGanttChart1.Project.Tasks.Clear;

    { States drive the timeline colors when DrawTasksByState is enabled. }
    LActive := TMSFNCGanttChart1.Project.States.AddState('In progress', gcOrange, 2);
    LDone := TMSFNCGanttChart1.Project.States.AddState('Done', gcGreen, 3);
    TMSFNCGanttChart1.Appearance.Options.DrawTasksByState := True;

    { Build a small dependent chain. }
    LBuild := TMSFNCGanttChart1.Project.AddTask('Build', 'Implement the feature',
      Trunc(Now), 5, gdtWorkDays, whWorkTimeAndDays, 100, LDone);
    LTest := LBuild.AddDependentTask('Test', 'Verify the feature',
      gtdFinishToStart, 3, gdtWorkDays, 0, gdtSeconds, whWorkTimeAndDays, 30, LActive);

    { A weekly group tier over daily cells. }
    TMSFNCGanttChart1.TimeLineOptions.GroupUnit := gtuWeek;
    TMSFNCGanttChart1.TimeLineOptions.TimeLineUnit := gtuDay;
  finally
    TMSFNCGanttChart1.EndUpdate;
  end;

  { Show only unfinished work, keeping the parent chain visible. }
  TMSFNCGanttChart1.Filter.FilterHierarchyMode := gfhParent;
  TMSFNCGanttChart1.Filter.Clear;
  TMSFNCGanttChart1.Filter.AddAND('progress', feoSmallerThan, 100);

  { Export the filtered view to PDF. }
  PDFIO.GanttChart := TMSFNCGanttChart1;
  PDFIO.GanttChartPDFExportOptions.Mode := emBoth;
  PDFIO.GanttChartPDFExportOptions.FitToPage := True;
  PDFIO.Options.PageOrientation := poLandscape;
  PDFIO.Save('open-work.pdf');
end;
void __fastcall TForm1::BuildFilterAndExport()
{
  TTMSFNCGanttTaskState *LActive, *LDone;
  TTMSFNCGanttTask *LBuild, *LTest;

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

    // States drive the timeline colors when DrawTasksByState is enabled.
    LActive = TMSFNCGanttChart1->Project->States->AddState("In progress", gcOrange, 2);
    LDone = TMSFNCGanttChart1->Project->States->AddState("Done", gcGreen, 3);
    TMSFNCGanttChart1->Appearance->Options->DrawTasksByState = true;

    // Build a small dependent chain.
    LBuild = TMSFNCGanttChart1->Project->AddTask("Build", "Implement the feature",
      Date(), 5, gdtWorkDays, whWorkTimeAndDays, 100, LDone);
    LTest = LBuild->AddDependentTask("Test", "Verify the feature",
      gtdFinishToStart, 3, gdtWorkDays, 0, gdtSeconds, whWorkTimeAndDays, 30, LActive);

    // A weekly group tier over daily cells.
    TMSFNCGanttChart1->TimeLineOptions->GroupUnit = gtuWeek;
    TMSFNCGanttChart1->TimeLineOptions->TimeLineUnit = gtuDay;
  }
  __finally
  {
    TMSFNCGanttChart1->EndUpdate();
  }

  // Show only unfinished work, keeping the parent chain visible.
  TMSFNCGanttChart1->Filter->FilterHierarchyMode = gfhParent;
  TMSFNCGanttChart1->Filter->Clear();
  TMSFNCGanttChart1->Filter->AddAND("progress", feoSmallerThan, TValue::From<int>(100));

  // Export the filtered view to PDF.
  PDFIO->GanttChart = TMSFNCGanttChart1;
  PDFIO->GanttChartPDFExportOptions->Mode = emBoth;
  PDFIO->GanttChartPDFExportOptions->FitToPage = true;
  PDFIO->Options->PageOrientation = poLandscape;
  PDFIO->Save("open-work.pdf");
}
A complete Gantt Chart project with state-colored bars, hierarchy, and dependencies A complete Gantt Chart project with state-colored bars, hierarchy, and dependencies

What this demonstrates

The routine ties together the individual chapters:

  1. Building — clears the default project and creates a Build → Test dependency chain inside a single BeginUpdate/EndUpdate block.
  2. States — registers "In progress" and "Done" states and turns on Appearance.Options.DrawTasksByState so bars are colored by status.
  3. Timeline — sets a weekly group tier over daily detail cells.
  4. Filtering — applies progress < 100 with gfhParent so only unfinished work shows while its parent chain stays visible.
  5. Export — points the PDF IO component at the chart and writes the filtered view to a landscape PDF.

Adapting it

Each step maps to a dedicated chapter, so swap pieces freely: change the filter to a different property, drive the states from loaded data, or replace the PDF export with printing. Because the filter is applied before export, the PDF reflects exactly what is on screen — apply or clear the filter first to control what gets exported.

See also