Table of Contents

Persistence

A project serializes its entire state — tasks, hierarchy, dependencies, the work-time calendar, and task states — to JSON, and reloads it. Use this to save a plan to disk, move it between application instances, send it over a network, or clone a project without sharing object references. Because the project is a non-visual data container, persistence is purely a data operation; the chart re-renders whatever the reloaded project contains.

Save and load JSON

The project exposes file, string, and stream variants. SaveToJSONFile / LoadFromJSONFile use a path; SaveToJSON / LoadFromJSON use a string; and SaveToJSONStream / LoadFromJSONStream use a TStream. Wrap a load in BeginUpdate/EndUpdate so the chart repaints once:

procedure TForm1.SaveProject;
begin
  // Persists tasks, dependencies, work-time calendar, states, and metadata.
  GanttProject1.SaveToJSONFile('project.json');
end;

procedure TForm1.LoadProject;
begin
  GanttProject1.BeginUpdate;
  try
    GanttProject1.LoadFromJSONFile('project.json');
  finally
    GanttProject1.EndUpdate;
  end;
end;

procedure TForm1.CloneProjectViaJSON(ASource, ATarget: TTMSFNCGanttProject);
var
  JSON: string;
begin
  // Copy a project between instances without sharing references.
  JSON := ASource.SaveToJSON;
  ATarget.LoadFromJSON(JSON);
end;

What gets stored

Persisted Notes
Tasks and hierarchy Names, descriptions, planned dates/durations, progress, cost, WBS structure
Dependencies Type, delay, and the target task reference
Work-time calendar Working days, working hours, and holidays
Task states The States collection and each task's assigned state
Project metadata ProjectName, ProjectId, Description

Application data fields (DataObject, DataPointer) hold runtime references and are not serialized — re-attach them after loading.

Cloning a project

Because save and load are symmetric, SaveToJSON followed by LoadFromJSON on a second project produces an independent copy. The third procedure in the snippet clones one project into another without sharing task instances — useful for a "what-if" scenario or an undo checkpoint.

Putting it together

Save and load compose into a clone operation: serialize the working project to JSON, then load that JSON into a second project to get an independent copy — useful for a "what-if" branch or an undo checkpoint:

procedure TForm1.SaveAndClone(ATarget: TTMSFNCGanttProject);
var
  JSON: string;
begin
  // Save the working project...
  JSON := GanttProject1.SaveToJSON;
  GanttProject1.SaveToJSONFile('project.json');

  // ...and load it into a second project as an independent clone.
  ATarget.BeginUpdate;
  try
    ATarget.LoadFromJSON(JSON);
  finally
    ATarget.EndUpdate;
  end;
end;

Pitfalls

  • DataObject / DataPointer are runtime references, not persisted; restore them after LoadFromJSON.
  • Load inside BeginUpdate/EndUpdate; otherwise each task added during the load triggers a recalculation.
  • A reloaded project replaces the current contents — save first if the existing data matters.
  • TTMSFNCGanttProjectSaveToJSON, LoadFromJSON, SaveToJSONFile, LoadFromJSONFile, SaveToJSONStream, LoadFromJSONStream

See also