Skip to main content

TdxGanttControlTaskPredecessorLinks.ToArray Method

Returns an array of dependecy predecessor identifiers.

Declaration

function ToArray: TArray<Integer>;

Returns

Type
TArray<T>

Remarks

This function returns identifiers of tasks to which the dependency belongs; otherwise, nil.

You can call the ToArray function to get a task’s predecessor as shown in the code example below:

var
  ADependencyCollection: TdxGanttControlTaskPredecessorLinks;
  ATask, APredecessor: TdxGanttControlTask;
  I: Integer;
  APredecessorArray: TArray<Integer>;
  APredecessorArrayItem: Integer;
begin
  for I := 0 to dxGanttControl1.DataModel.Tasks.Count - 1 do
  begin
    // Initializes a task
    ATask := dxGanttControl1.DataModel.Tasks[I];
    // Initializes a dependency collection
    ADependencyCollection := ATask.PredecessorLinks;
    // Checks if the dependency count exceeds 0
    if ADependencyCollection.Count > 0 then  
    begin
      // Adds the ToArray function result to the array of predecessor UIDs
      APredecessorArray := ADependencyCollection.ToArray;
      // Iterates through array items
      for APredecessorArrayItem in APredecessorArray do
      begin
        // Accepts only predecessor tasks. Unique identifiers of these tasks should belong to the array of predecessor tasks' UIDs
        APredecessor := dxGanttControl1.DataModel.Tasks.GetItemByUID(APredecessorArrayItem);
        // Checks if there are predecessor tasks
        if APredecessor <> nil then 
        // Adds checking result to the cxMemo1 control
          cxMemo1.Lines.Add(Format('The ''%s'' task is the predecessor of the ''%s'' task.', [APredecessor.Name, ATask.Name]));
      end;
    end;
  end;
end;
See Also