Questions on Planner

I still have work to do to tidy it up. But I have two questions.

  1. Why does display starts at position 5 on the LHS?
    • I am clearing Resources and Items.
    • And I have verified that I am assigning positions starting at 1.
    • What haven't I cleared?
    • I haven't found anything in Position or Resources that could be an offset.
  2. I haven't figured out yet, how to display Date on the top.
    • Ideally Date and Day of Week
    • I don't want hours displayed at all.

  1. There is a TimeLine.ViewStart property to control where the planner is initially focused during start.
  2. You can use the following event to custom draw time in the time-line
procedure TForm6.TMSFNCPlanner1BeforeDrawTimeText(Sender: TObject;
  AGraphics: TTMSFNCGraphics; ARect: TRectF; AValue: Double; ARow: Integer;
  ASubUnit: Boolean; AKind: TTMSFNCPlannerCacheItemKind; AText: string;
  var AAllow: Boolean);
begin
  AAllow := False;
  if not ASubUnit then
    AGraphics.DrawText(RectF(ARect.Left, ARect.Top, ARect.Left + 100, ARect.Bottom), FormatDateTime('dd.mm.yyyy', AValue), False, gtaLeading, gtaLeading);
end;
  1. My issue is the position of the Position/Resource, not the timeline (atm). Its suspicious as there are 5 positions loaded by default. But I am clearing the collections/lists.
  2. I will try the event once I have exhausted other settings, thanks

A bit more debugging.

I am doing a Items.Clear and Items.Count is indeed 0. However, the first item I create gets the ID=5. That's what was throwing me. There is no offset, all my items are in view, its just that the ID starts at 5.

It's unclear exactly where ID is coming from but it's not a property for TTMSFNCPlannerItem, can you provide some insight into your code?

The first time it starts with 5. If I then switch to a different Resource Type (say Pilots to Fuel), it continues from what it had reached to.

Its an internal ID, but it never resets. I am Clearing Items and Resources. Do I have to clear some other collection/list ?

procedure TPln_Data.dba_ItemRead
          (Sender : TObject;
           AItem  : TTMSFNCPlannerItem);

var
  LRes_Ref     : Int64;
  LRes_Ref_Str : string;

  procedure Get_Custom_Data;
  var
    LExtra : TPln_Extra_Data;
  begin
    LExtra := TPln_Extra_Data(AItem.DataObject);
    if Assigned (LExtra)
    then begin
         LRes_Ref := LExtra.Resource_Ref;
    end
    else begin
         LRes_Ref := 0;
    end;
    LRes_Ref_Str := IntToStr (LRes_Ref);
  end;

  function New_Resource_Name : string;
  var
    LName : string;
  begin
    case FPlanner of
      pt_Pilots   : LName := PL.Pilot_Data    [LRes_Ref]._Display;
      pt_Crew     : LName := PL.Crew_Data     [LRes_Ref]._Display;
      pt_Aircraft : LName := PL.Aircraft_Data [LRes_Ref]._Display;
      pt_Fuel     : LName := PL.Fuel_Data     [LRes_Ref]._Display;
      else          LName := '';
    end;
    if FShow_Res_Ref
    then Result := LName + '(' + LRes_Ref_Str +  ')'
    else Result := LName;
  end;

  procedure Assign_Resource_Number;
  var
    LRes_Idx_Str : string;
    LRes_Idx     : Integer;
    LPln_Res     : TTMSFNCPlannerResource;
  begin
    { Index to Planner Resources Collection }
    LRes_Idx_Str := FResource.Data [LRes_Ref_Str];

    if LRes_Idx_Str = ''
    then begin
         LPln_Res      := Fpln.Resources.Add;
         LPln_Res.Text := New_Resource_Name;
         LRes_Idx      := LPln_Res.Index;
         { Store the Planner Resources Index }
         FResource.Data [LRes_Ref_Str] := IntToStr (LRes_Idx);
         TConsole.Log ('dba_ItemRead - Added resource', LRes_Ref_Str);
    end
    else begin
         TryStrToInt (LRes_Idx_Str, LRes_Idx);
    end;
    AItem.Resource := LRes_Idx;
  end;

(*
var
  LID          : Int64;
  LPln_Res_Ref : string;
*)
begin
(*
  LID           := AItem.ID;  // First ID is 5 for some reason  <-------------------------------------------
  LPln_Res_Ref  := AItem.DBKey;
*)
  Get_Custom_Data;
  Assign_Resource_Number;

   { TODO 1 -oFeature -cUrgent : Put Def Pilot/Crew in setup }
   { TODO 1 -oFeature -cUrgent : Use Filter and Order by Ref/Start_Time}
end;

ID is a property of TCollectionItem.

It's not used in TTMSFNCPlanner.

Thats really strange. When I am back on the planner code, I will have to check the TCollection source to see why Items.Clear is not resetting it.

You might want to use .Index instead of .ID