Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract an object from a TObjectList

I have a TObjectList with OwnsObjects = true. It contains quite a few objects. Now I want to remove the object at index Idx from that list, without freeing it.

Is the Extract method the only option?

ExtractedObject := TheList.Extract(TheList[Idx]);

All other methods seem to free the object. I am looking for something a little bit more efficient, that does not do a linear search every time, since I already know the index of the object. Something like an overloaded ...

ExtractedObject := TheList.Extract(Idx);

... which does not exist.

like image 666
Thomas Mueller Avatar asked Apr 09 '26 05:04

Thomas Mueller


1 Answers

Why not just set OwnsObjects to false, do your removal, then set it to true again?

like image 126
skamradt Avatar answered Apr 10 '26 22:04

skamradt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!