Tasks: IPrjTaskCollection;
The Tasks property returns the tasks collection.
To execute the example, add a link to the ProjectPlanning system assembly.
Sub UserProc;
Var
Project: IPrjProject;
Calendar: IPrjCalendarOptions;
DTar: Array Of DateTime;
Tasks: IPrjTaskCollection;
Task: IPrjTask;
Depend: IPrjTaskDependency;
FPeriod: IPrjTaskPeriod;
i: Integer;
Begin
Project := New PrjProject.Create;
// Set project start date
Project.StartDate := DateTime.Parse("20.02.2020");
Project.UseStartDate := True;
// Get calendar settings
Calendar := Project.CalendarOptions;
Calendar.IncludeWeekend := False;
// Set two holidays
DTar := New DateTime[2];
DTar[0] := DateTime.Parse("23.02.2020");
DTar[1] := DateTime.Parse("08.03.2020");
Calendar.ExcludedDates := DTar;
// Get collection of project tasks
Tasks := Project.Tasks;
// Add the first task
Task := Tasks.Add;
Task.Key := 1;
Task.Name := "№1";
Task.PlanPeriod.Duration := 8;
// Add the second task
Task := Tasks.Add;
Task.Key := 2;
Task.Name := "№2";
Task.PlanPeriod.Duration := 10;
Depend := Task.Dependencies.Add;
Depend.PredecessorTaskKey := 3;
Depend.Type := PrjTaskDependencyType.FinishToFinish;
// Add the third task
Task := Tasks.Add;
Task.Key := 3;
Task.Name := "№3";
Task.PlanPeriod.Duration := 12;
Depend := Task.Dependencies.Add;
Depend.PredecessorTaskKey := 1;
Depend.Type := PrjTaskDependencyType.FinishToStart;
// Run calculation
Project.Plan;
Debug.WriteLine("Project start date: " + Project.StartDate.ToString);
For i := 0 To Tasks.Count - 1 Do
Task := Tasks.Item(i);
FPeriod := Task.ForecastPeriod;
Debug.WriteLine(" Task execution " + Task.Name + " from " +
FPeriod.StartDate.ToString + " to " + FPeriod.FinishDate.ToString +
" (duration: " + FPeriod.Duration.ToString + " days)");
End For;
Debug.WriteLine("Forecasted project end date: " + Project.EndDate.ToString);
End Sub UserProc;
After executing the example, the project will be calculated considering the specified conditions:
Saturday and Sunday are non-working days and they are not included into calculation.
The 23 February and the 8 March are holidays and are not included into calculation.
The project start date matches the first task start date.
The second task execution end date matches the third task end date.
The third task execution start date depends on the first task en date.
The console displays the calculation result:
Project start date: 20.02.2020 00:00:00
The first task execution from 20.02.2020 00:00:00 to 02.03.2020 00:00:00 (duration: 8 days)
The second task execution from 05.03.2020 00:00:00 to 18.03.2020 00:00:00 (duration: 10 days)
The third task execution from 03.03.2020 00:00:00 to 18.03.2020 00:00:00 (duration: 12 days)
The forecasted project end date: 18.03.2020 00:00:00
See also: