DBPlanner .Object property

I want to use the Item.Object property to store custom data instead of a descendant class. What is not clear is from which events to read and write the data. I need access to the Item.ID value for sure. In DBDaySource.ItemToFields event when adding an item the Item.ID is 0 for example.

DBxxxSource.OnItemToFields to write data back to the DB from the item

DBxxxSource.OnFieldsToItem to initialize item properties from DB fields

PlannerItem.ID is a free to use property and has no purpose in the Planner, so it is normal that when you do not use this, it will be 0.

Right. I am not explaining this properly. I use the ID property to store the unique item ID field in the database. In DBDaySource.ItemToFields for a new item the item ID will not have been created yet. but I need it to store the custom data properly. What event can I access the item ID and then populate the .Object so it is available to the edit form?

I do not know when you can or want to set the .ID property, so I can only suggest to set the object after you set the ID if your object depends on your ID.

I am possibly over-complicating this. Forget the Item.ID value. On creating a new item, before showing the item edit dialog, the item is saved to the database. At this time the Item ID field value in the table will be auto-created. How can I access this new item ID value? I need the ID at this time to save linked data to another table.

TDBPlanner is not doing anything itself with PlannerItem.ID.

TDBPlanner uses PlannerItem.DBKey to store the unique key field value and when auto key generation is enabled, TDBPlanner will set this PlannerItem.DBKey value to a GUID when a new item is created.

OK great. So I resolved this problem by using the DBKey to get the autoinc ID from the table. It works but is a bit kludgy. The manual seems to suggest you can use an auto-increment field value for the Key field instead of a GUID by coding the OnCreateKey event. I don't see how this would work but that would be the ideal solution for me. Simply reading the last value and incrementing would not seem safe in a multi-user setting.

Set AutoIncKey = true when you have an auto-inc DB field, i.e. your DB will be responsible for unique key generation and if your DB is multi user capable, it will be reliable.