I know the benefits of const
parameters for simple types and strings in Delphi. But what about a const TStrings
? Since a const TStrings
parameter can have its items (content) changed, what's the point of declaring a const TStrings
parameter for example? This applies to any object too.
To declare a record constant, specify the value of each field - as fieldName: value , with the field assignments separated by semicolons - in parentheses at the end of the declaration. The values must be represented by constant expressions.
Description. Delphi extends the const keyword of standard Pascal by allowing you to specify any constant-valued expression as the value of a constant and by allowing you to give a specific type for a constant.
The const
applies only to the pointer to the TStrings
object, not to the TStrings
object itself. So it really makes little difference on non-ARC based platforms, especially if the code does not try to change where the pointer is pointing to. It's only real use is to document the intention of the parameter.
But, the const
can make a BIG difference on ARC-based platforms. It disables implicit reference counting on the object that is passed to the parameter (just as const
does for string and interface parameters).
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