Persisting tasks (JSON and CSV)
Tasks can be saved to and loaded from JSON or CSV without a database. JSON preserves the full task tree, dependencies, and states and is the right choice for round-tripping a project; CSV is a flat, delimited export suited to spreadsheets or interchange. Loading replaces the tasks currently in the project, so save first if you need to keep them.
procedure TForm1.SaveAndReload;
begin
{ JSON keeps the full task tree, dependencies and states. }
TMSFNCGanttChart1.SaveTasksToJSONFile('tasks.json');
{ CSV is a flat export; pass the delimiter that matches your locale. }
TMSFNCGanttChart1.SaveTasksToCSVData('tasks.csv', boBinary, ';');
{ Loading replaces the tasks currently in the project. }
TMSFNCGanttChart1.LoadTasksFromJSONFile('tasks.json');
TMSFNCGanttChart1.LoadTasksFromCSVData('tasks.csv', ';');
end;
void __fastcall TForm1::SaveAndReload()
{
// JSON keeps the full task tree, dependencies and states.
TMSFNCGanttChart1->SaveTasksToJSONFile("tasks.json");
// CSV is a flat export; pass the delimiter that matches your locale.
TMSFNCGanttChart1->SaveTasksToCSVData("tasks.csv", boBinary, L';');
// Loading replaces the tasks currently in the project.
TMSFNCGanttChart1->LoadTasksFromJSONFile("tasks.json");
TMSFNCGanttChart1->LoadTasksFromCSVData("tasks.csv", L';');
}
File methods
| Method | Purpose |
|---|---|
SaveTasksToJSONFile / LoadTasksFromJSONFile |
Round-trip the whole task tree, dependencies, and states. |
SaveTasksToCSVData / LoadTasksFromCSVData |
Flat delimited export/import. |
SaveTasksToCSVData(AFileName, ABooleanOutput, ADelimiter) lets you choose how
boolean fields are written — boBinary (0/1) or boTrueFalse — and which
delimiter to use. Pass the delimiter that matches the locale of the consuming
tool (for example ';' where comma is the decimal separator).
Stream variants
When you are not writing to disk — embedding data in another document, sending it
over a connection, or storing it in a blob — use the stream overloads:
SaveTasksToJSONStream/LoadTasksFromJSONStream and
SaveTasksToCSVStreamData/LoadTasksFromCSVStreamData. They take a TStream instead
of a file name and otherwise behave identically.
What is preserved
JSON captures the hierarchy, dependencies, durations, work-time policy, progress, and state assignments, so a saved project reloads exactly. CSV is intentionally flat: it is best for exchanging the task list with tools that expect tabular data, not for preserving the full dependency graph.
Putting it together
Round-trip the task tree through both a file and a stream using the same JSON format:
procedure TForm1.RoundTripTasks;
var
LStream: TMemoryStream;
begin
{ File methods. }
TMSFNCGanttChart1.SaveTasksToJSONFile('tasks.json');
TMSFNCGanttChart1.LoadTasksFromJSONFile('tasks.json');
{ Stream variants: the same JSON format through a TStream. }
LStream := TMemoryStream.Create;
try
TMSFNCGanttChart1.SaveTasksToJSONStream(LStream);
LStream.Position := 0;
TMSFNCGanttChart1.LoadTasksFromJSONStream(LStream);
finally
LStream.Free;
end;
end;
void __fastcall TForm1::RoundTripTasks()
{
TMemoryStream *LStream;
// File methods.
TMSFNCGanttChart1->SaveTasksToJSONFile("tasks.json");
TMSFNCGanttChart1->LoadTasksFromJSONFile("tasks.json");
// Stream variants: the same JSON format through a TStream.
LStream = new TMemoryStream();
try
{
TMSFNCGanttChart1->SaveTasksToJSONStream(LStream);
LStream->Position = 0;
TMSFNCGanttChart1->LoadTasksFromJSONStream(LStream);
}
__finally
{
delete LStream;
}
}
See also
- Exporting to PDF and printing — produce a shareable rendering.
TTMSFNCGanttChartAPI