Moving linked items off planer

When a linked item is moved off the planner. (eg push off to the right)



- The planner seems to make the item sizes go the full length of the planner. 
- Or the items are lost, pulling the linked item back to the left will have no linked item

Is there a step i am missing? or do I need to perform extra checks in Item Move

Example images:

https://1drv.ms/i/s!Al20CEDWSAKtqvlh4YQ6D5SlGPZ2kg

I have worked around it using PlannerItemMoving and restricting the movement. 

The code below does not take non visible items and I am treating every item in future as linked. so you would need to adjust GetMaxItemEnd for you own needs.

Happy for feedback for another suggestion still.






function GetMaxItemEnd(AItem: TPlannerItem): Integer;
var
  LPlannerItem: TPlannerItem;
  LIdx, LItemLength: Integer;
begin
  Result := AItem.ItemEnd;
  LPlannerItem := AItem;
  For LIdx := 0 to Pred(Planner.Items.Count) do
  begin


    LPlannerItem := Planner.Items[LIdx];
    If Assigned(LPlannerItem) then
    begin
     // Adjust criteria is needed.
      if (LPlannerItem.ItemBegin > AItem.ItemBegin) and (LPlannerItem.ItemPos = AItem.ItemPos) and (not LPlannerItem.Background) and
          (not LPlannerItem.FixedPosition) then
      begin
        if LPlannerItem.ItemEnd > Result then
          Result := LPlannerItem.ItemEnd;
      end;
    end;
  end;
end;



procedure TForm1.PlannerItemMoving(Sender: TObject; Item: TPlannerItem; DeltaBegin, DeltaPos: Integer; var Allow: Boolean);
var
  LAllow: Boolean;
  LMaxItemEnd: Integer;
begin
  LAllow := true;
  if Item.LinkedItem <> nil then
  begin
    if (Item.ItemPos + DeltaPos) <> Item.ItemPos then
    begin
      // Don;t allow change of position if linked.
      LAllow := False;
    end;
    LMaxItemEnd := GetMaxItemEnd(Item);
    if (LMaxItemEnd + DeltaBegin) > (Planner.Display.DisplayEnd + 1) then
    begin
      // Don't allow moving beyond planner display end.
      LAllow := False;
    end;
  end;
  if not LAllow then
    Abort;
end;

Limiting the movement is indeed a possible solution. At the same time, we have also applied an improvement that prevents that the linked item size is affected by being moved completely off the timeline.