Closed Fengist closed 3 years ago
Do you have a demo application?
I'm working on one but it uses a pretty specific set of directories and .cfg files. Do you happen to own Kerbal Space Program? If so, I can package it up for you. If not:
Basically, I'm trying to import something that's a cross between an INI file and a JSON or XML and put it into the inspector grid. The original .cfg file looks sorta like this. Where it's loaded in the inspector is in parenthesis.
PART (itParent, level 0, index 0) { MODULE (itParent, level 1, index 1) { name = this name (itString, level 2, index 2) ANOTHERMODULE (itParent, level 2, index 3) { name = another name (itString, level 2, index 4) } } }
As long as I load the file sequentially into the inspector, it does it perfect. It's when I try to add or insert a new itParent that it gets confused. If for example I try to add an itParent at the 'MODULE' location, it'll place it at index 0 level 1. If I try to insert at that location, it places the new itParent at index 0 level 0. Both end up appearing in the inspector above the 'PART'.
I tried to trace through the insert function and from what I can tell, even though there is a parent assigned it never recognizes it has a parent, assumes the parent is nil and the variable OK never gets set to true so it puts it in the root location at level 0. Just goofing off, in InsertItem I changed
if not ok then begin to if ok then begin
and it added the new itParent to index 0 but with the proper level, essentially reproducing the same error with the add.
For now I've taken out the add and inserts and am having to go the long way around to solve this. I'm exporting the inspector to a csv, inserting or adding to the csv then reloading the entire thing back into the inspector. Very tedious.
Also found another bug due to my ignorance.
if you
grid.ItemCollection.BeginUpdate and then grid.ItemCollection.Clear;
it produces a list index out of bounds error.
But, if you do a grid.BeginUpdate and then grid.ItemCollection.Clear
it works as intended. Let me know and I can start a new ticket on that one if you wish.
I never heart about the Kerbal Space Program.
Feel free to open another ticket for the ItemCollection.
Currently I'm very busy. So I guess I will not find enough time to fix the bugs... It would be great if you could find them.
Here's the setup.
I have an inspector with the root node being a type itParent. It has multiple type itString and itParents below it. When attempting to add or insert a type itParent to one of the itParent nodes, it only inserts properly if the root parent or the last parent are selected. If an itParent is selected in the middle of the inspector, the new itParent gets inserted with an index of 0 even though it's parent's index is a much higher number.
Here's the simple code I'm using trying to add a new parent. The 'Selected' is of type itParent.
The problem seems to occur in TO32InspectorItem.SetIndex. New ID keeps getting decremented till it reaches 0. Test1 and Test2 always evaluate to true because Parent=nil and Self seems to be set to the last item on the list.
If I sort the grid, the inserted item appears under the proper parent. Unsorted, it does not. If I export the grid to text, the inserted item appears at index 0.
edit
I've done some more testing and here's what I can tell you. Both add and insert fail to place a new itParent in the proper location when the parent is not on level 0. Originally, I had the entire grid filled off one parent and both add and insert were unable to locate a new itParent in the proper location. I removed that root parent and add and insert were then able to place a new itParent provided that the parented item was on level 0.