Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TdxGanttControlTaskPredecessorLinks.ToArray Method

Returns an array of dependecy predecessor identifiers.

#Declaration

Delphi
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