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.
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");
}
What this demonstrates
The routine ties together the individual chapters:
- Building — clears the default project and creates a
Build → Testdependency chain inside a singleBeginUpdate/EndUpdateblock. - States — registers "In progress" and "Done" states and turns on
Appearance.Options.DrawTasksByStateso bars are colored by status. - Timeline — sets a weekly group tier over daily detail cells.
- Filtering — applies
progress < 100withgfhParentso only unfinished work shows while its parent chain stays visible. - 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
- Building a project · Task states · Timeline configuration
- Filtering tasks · Exporting to PDF and printing
- Common pitfalls — avoid the usual mistakes.