10484 : How can I iterate trough all the rows of the grid and gantt rows then save them to a database and later on read them in again. VCL

Question

I just received my legal copy of phgant vcl component. I am missing a serious help file.

How can I iterate trough all the rows of the grid en gantt rows en save them to a database and later on read them in again. I know how to use the database component but I don’t see a way to iterate through all the items An small exemple for delphi vcl please

Answer

We are sadly aware of the poor state of the help file; we have been a bit surprised by the recent revival of the phGantTimePackage for VCL. Of course we will make up for it by answering all question swiftly;

One possible way to bridge the gap between the ActiveX help file and knowledgebase and the VCL version is to look at the “glue” files that wrap the VCL version to create the ActiveX.
You can then directly see what internal VCL calls that are made to get a certain ActiveX call. Email support if you want access to these pas files

This code iterates the complete Gantt (instanse called G1)


procedure TForm1.ButtonIterateClick(Sender: TObject);

  procedure IterateCellsInANode(aGridRow:TAxisContentItem);
  var
    x:integer;
  begin
    for x:=0 to G1.Grid.CellCountX-1 do
    begin
      G1.Grid.GetText(G1.Grid.Cell[x,aGridRow.ListIndex]);
    end;
  end;

  procedure IterateGanttRowContent(aGantRow:TGantRow);
  var
    i,ii:integer;
    aTimeItem:TphDataEntity_GantTime;
  begin
    // Iterate layers
    for i:=0 to aGantRow.DataLists.Count-1 do
    begin
      // for each layer iterate time items
      for ii:=0 to aGantRow.DataLists.Items[i].Count-1 do
      begin
        aTimeItem:=aGantRow.DataLists.Items[i].Items[ii] as TphDataEntity_GantTime;
        aTimeItem.Start:=aTimeItem.Start+1; // Just change something so that we see that we have been here
        aTimeItem.Stop:=aTimeItem.Stop+1;
      end;

    end;
  end;

  procedure IterateNode(aNode:TphDataEntity_GridTreeNode);
  var
    i:integer;
  begin
    // Iterate sub nodes of this node
    for i:=0 to aNode.SubDataList.Count-1 do
    begin
      IterateNode(aNode.SubDataList[i] as TphDataEntity_GridTreeNode);
    end;
    IterateCellsInANode(aNode.AxisContentItem);
    IterateGanttRowContent(G1.RowList.FindRowFromGridNode(aNode));
  end;


var
  i:integer;
begin
  // Iterate root nodes from the grid tree
  for i:=0 to G1.Grid.GetTree.RootDataEntities.Count-1 do
  begin
    IterateNode(G1.Grid.GetTree.RootDataEntities[i] as TphDataEntity_GridTreeNode);
  end;
  G1.GA.Invalidate; // Invalidate the Gantt area to show changes

end;

Leave a Reply