See here:
https://forum.lazarus.freepascal.org/index.php/topic,41857.msg291278.html#msg291278A few other notes (those are compiler internals, that can change in future)
- const for integer may not do anything at all (other than giving you an error if you try to write to the param
- const allows large records to be passed as pointer to the callers data (since the data is not going to be changed / neither in the param, nor via a global var, nor otherwise)
This saves copying the memory of the record
- const for strings (and dyn array / all managed ref counted types), allows to "not increase the ref count". That does save time. But it also means that other code doesn't know you have a copy of the string (and so if the string is modified, its memory can be reallocated and the param is invalid after that)
And your conclusion is (nearly) spot on
but of course since the const parameter references the variable that was changed it would have new value.
Since ansistrings are already pointers to the text, the param would be a copy of the pointer. So that copy in the param would not change. But the text to which is pointed was changed (it was moved elsewhere in mem).
Basically your ansistring was downgraded to pchar in the parameter.