TDBPlanner - TDBDaySource - New item

I have returned to completing the Planner.
He always writes to me in DB:
Date: The first day displayed on the calendar
Time: 14.00 - 14.30

dbplDay.CreateItem;

procedure TfrmPlannerRole.dbpmwMonthCreateKey(Sender: TObject; APlannerItem: TPlannerItem; var Key: string);
begin
  APlannerItem.CaptionText := 'Vytvorené automaticky';
  APlannerItem.Text.Text := 'Táto udalosť bola vytvorená programovo';
  APlannerItem.Tag := 0;
  APlannerItem.Shape := TPlannerShape(0);
  APlannerItem.CaptionType := TCaptionType(1);
  APlannerItem.DBKey := '-1';
  APlannerItem.Update;
  fdtblPlanner.Insert;
end;

I have no idea why you are using OnCreateKey for something it is not intended to be used.
The only thing that should happen in OnCreateKey is set the var Key parameter (only if you wish to dynamically customize this key, otherwise, do NOT use this event).

All right. You just didn't write me what to use. I am currently reading the instructions. Maybe I'll find out :grinning:

It would be helpful if you asked what exactly you want. I see no question.
I cannot give you the answer you expect if you don't ask a question.
Helpful in this context: TMS Software | Blog

I want to create a new item in TDBPlanner
One of the options is:
procedure TfrmPlannerRole.dbplDayPlannerDblClick(Sender: TObject; Position, FromSel, FromSelPrecise, ToSel, ToSelPrecise: Integer);

Apart from Position, there is not a word in the manual about what the individual parameters mean. How should I work with it?
I need to convert that cell to a date and time. How?
You have some examples there, but not this case.
I have a popup menu defined, but I will have to convert the mouse coordinates to the date and time. I saw something in the manual. So fast.

I don't know English. So I just take the written text.

OT: For me as a "programmer " there is nothing on the blog :frowning_face:
The topic name is "New Item"

Um, I was able to find something:

procedure TForm1.Planner1PlannerKeyPress(Sender: TObject; var key:char; position, fromSel, fromSelPrecis, toSel, toSelPrecis: Integer);
begin
  with planner1.Items.Add do
  begin
    itempos := position;
    itembegin := fromSel;
    itemend := toSel;
    captiontype := ctTime;
    Text.Add(key);
    Edit;
    planner1.MemoEdit.SelStart := 1;
    planner1.MemoEdit.SelLength := 0;
  end;
end;

If I use dbplDay.Items.Create, the OnItemToFields event fires before the data is populated. And I'm in ...
How do I get a created item?
How can this be done without "with". This design is not recommended.

procedure TfrmPlannerRole.dbplDayPlannerDblClick(Sender: TObject; Position, FromSel, FromSelPrecise, ToSel,
  ToSelPrecise: Integer);
var
  Item: TPlannerItem;
begin
  with dbplDay.Items.Add do
  begin
    DBKey := IntToStr(NewPrimaryKey);
    ItemPos := Position;
    ItemBegin := FromSel;
    ItemBeginPrecis := FromSelPrecise;
    ItemEnd := ToSel;
    ItemEndPrecis := ToSelPrecise;
    CaptionType := ctTime;
    Text.Add('Vytvorené programovo');
    ImageID := - 1;
    Flashing := False;
    Shape := TPlannerShape(0);
  end;

  fdtblPlanner.Insert;
  fdtblPlanner.FieldByName('IDPLANNERS').AsInteger := StrToInt(Item.DBKey);
...
  fdtblPlanner.Post;
end;
procedure TfrmPlannerRole.dbplDayPlannerDblClick(Sender: TObject; Position, FromSel, FromSelPrecise, ToSel,
  ToSelPrecise: Integer);
var
  Inputs: array [0..0] of TInput;
begin
  ZeroMemory(@Inputs, SizeOf(Inputs));
  Inputs[0].Itype := INPUT_KEYBOARD;
  Inputs[0].ki.wVk := VK_INSERT;
  SendInput(1, Inputs[0], SizeOf(TInput));
end;

The Position, FromSel,ToSel parameters indicate the coordinates of the timeslot selected.
An item could as such be created with

var
  it: TPlannerItem;
begin
  it := Planner.CreateItem;
  it.ItemBegin :=  FromSel;
  it.ItemEnd :=  ToSel;
  it.ItemPos := Position;
end;