is it possible to make a Delphi TList immutable?
I searched in the delphi doc for a class similar to the unmodifiableList in java, but didn't found anything.
regards!
You could use the IReadOnlyList<T>
from Spring4D.
If you have an IList<T>
you just call AsReadOnlyList
(AsReadOnly
since 2.0) and it returns you the same instance as IReadOnlyList<T>
which does not provide methods to manipulate the list (no Add
, Delete
or setter for the Items
property).
However there is a difference to the unmodifiableList
from Java:
In Java you really get a List<T>
which will throw UnsupportedOperationException
when you try to modify it while in Spring4D which is mostly modeled after .NET you get something that you cannot call any modifying operations on.
The Delphi RTL contains no classes that implement immutable or read-only lists. You will have to implement such a class yourself, or find a library that offers such functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With