Prof Abimbola Olowofoyeku wrote:
Yes, I am confusing them. It would be nice to be able to increase the capacity though. Perhaps some compiler magic can just treat a call to something like "SetCapacity" as the declaration of a new variable, and then allocate the appropriate storage to it. An extension of this might be that, any attempt to assign a value that is longer than the current capacity should be treated as equivalent to: SetCapacity (s, length (newvalue)); s := newvalue;
For "normal" global and local strings that's just impossible because the size can't be changed afterwards once their address in memory is fixed.
With this, you can have dynamically growing strings. Perhaps I am just being naïve in thinking that this can be done at all, or that, even if it can be done, it will not involve a major and/or undesirable changes to the compiler. But if I were to implement something like Delphi's "AnsiString", I might well consider something like this.
As you might know, this is planned, but it will involve bigger changes, e.g. because such variables will have to be implemented via pointers internally so changing the size becomes possible at all.
Frank