Parent Child Table (part 5)
This brings us to the Delete. The changes needed in the delete are very straight forward. As you probably expect we must iterate the child collection, and call it's Delete Procedure on each record. When that is complete, we are free to delete the Parent Record.
If DeleteValidate(*Class) = #False
ProcedureReturn #False
Else
;=======================================================
ForEach *Class\SolarSystemCollection()
SOLARSYSTEM::Delete(*Class\SolarSystemCollection())
Next
;=======================================================
DBID = DB::Open(DBTYPE::#Sqlite)
SetDatabaseLong(DBID, 0, *Class\ID)
Sql$ = " DELETE "
Sql$ = Sql$ + "FROM "
As there are NO changes to the Validate and DeleteValidate steps, you might be thinking we are done but there are several more NEW Procedures we will need to add to the Module.
These are hybrid List Procedures, only these lists will pull from our Collection and NOT the Database. We only want to use the database for saving and loading our Child Records. When listing the "Current" Children, we need to list the Records of the Parent NOT the Database.
So the obvious list procedures we will need are the LoadComboBox, and the LoadListIcon. I suppose you could add the ListView, but I've found thar I personally have no use of that Gadget. But I'll go ahead and include him in our module.
Procedure LoadComboBoxSolarSystemCollectionName(cbData.i, *ChildSolarSystemCollection())
ComboBoxEx::ClearItems(cbData)
ForEach *ChildSolarSystemCollection()
ComboBoxEx::AddItem(cbData, -1, *ChildSolarSystemCollection()\Name)
ComboBoxEx::SetItemData(cbData, ComboBoxEx::CountItems(cbData), *ChildSolarSystemCollection()\ID)
Next
EndProcedure
Procedure LoadListViewSolarSystemCollectionName(lvData.i, *Child.SolarSystemCollection())
ClearGadgetItems(lvData)
ForEach *ChildSolarSystemCollection()
AddGadgetItem(cbData, -1, *ChildSolarSystemCollection()\Name)
SetGadgetItemData(cbData, CountGadgetItems(cbData), *ChildSolarSystemCollection()\ID)
Next
EndProcedure
Above are the LoadComboBox, and LoadListView Procedures, and below is the LoadListIcon Procedure being loaded from the child collection.
Procedure ListIconSolarSystemCollection(liData.i, *Child.Galaxy)
ListEx::DisableReDraw(liData, #True)
ListEx::ClearItems(liData)
ListEx::RemoveColumn(liData, 0)
ListEx::RemoveColumn(liData, 0)
ListEx::RemoveColumn(liData, 0)
;===== Build Column Titles =====
ListEx::AddColumn(liData, 0, "Name", 175)
ListEx::AddColumn(liData, 1, "Row", 70)
ListEx::AddColumn(liData, 2, "Col", 70)
ListEx::SetColumnAttribute(liData, 0, ListEx::#Align, ListEx::#Left)
ListEx::SetColumnAttribute(liData, 1, ListEx::#Align, ListEx::#Center)
ListEx::SetColumnAttribute(liData, 2, ListEx::#Align, ListEx::#Center)
;===== Populate Data Into Column =====
ForEach *Child\SolarSystemCollection()
ListEx::AddItem(liData, -1, ListIconItemSolarSystem(*Child\SolarSystemCollection()))
ListEx::SetItemData(liData, ListEx::CountItems(liData)-1, *Child\SolarSystemCollection()\ID )
Next
ListEx::DisableReDraw(liData, #False)
EndProcedure
Procedure.s ListIconItemSolarSystem(*Class.SOLARSYSTEM::SolarSystem)
Protected lvItem$
lvItem$ = *Class\Name + #LF$ + Str(*Class\GRow) + #LF$ + Str(*Class\GCol) + #LF$
ProcedureReturn lvItem$
EndProcedure
I have broken the LoadListIcon Collection Procedure, into two Procedures, Relegating the building of the ListViewItem or Row into a separate Procedure. I do this to make the code easier to read, and digest, but MOSTLY because in my screens when Loading and Displaying the Collection ListIcon to the user and adding records they create in forms I can Reuse this Second Procedure from my screen code.
Comments
Post a Comment