In Delphi 6, if you try to insert an object into a TStringList that is sorted (Sorted = true), an exception is raised warning that InsertObject () is not allowed in the sorted list. I could understand this if calling the InsertObject () function necessarily meant destroying the ordered order of the list. But considering that the TStringList.Find () method:
function TStringList.Find(const S: string; var Index: Integer): Boolean;
returns an index indicating exactly what the insert index should be for the given row, if it was added to the list, calling the InsertObject () method with this index should leave the sorted list in sorted order after the operation. I studied the Delphi source for the TStringList and seems to have confirmed my claim.
For now, I am just creating a new subclass for TStringList that overrides InsertObject () and does not throw an exception if InsertObject () is called in a sorted list, but I want to make sure that there are no hidden dangers that I just donβt see.
- roschler
source share