Should this function parameter not also be const declared because of refcount issues?
No, because objects are not reference-counted. Strings are, interfaces are, but objects are not.
Now I am confused. Should I use the first or the second code?
Use whichever one suits your needs.
However, most devs feel that having a function return a new dynamically-allocated object that the caller is expected to free is not a good design choice. The caller should create its own object however it wants, and then the function should merely populate that object with data as needed. The caller can then decide what to do with the object afterwards. But design is more of a personal choice.
Personally, I wouldn't even bother using such simple functions. They don't really add much value to code (especially
TStrings2String()). If a caller already has access to a
TStrings object, it could just read the
Text property directly, and assign the
Text property directly.
And if the second, should'nt it be "Var strs..." in the declaration, because the variable gets modified?
No, because the function is not modifying the passed pointer itself to point at a different object. It is modifying the contents of the object that is being pointed at. Two different scenarios.