What is the default value of ‘Result’ in Delphi?

A function return value of type string is actually treated by the compiler as an implicit var parameter. When the function begins execution, the Result variable contains whatever is in the local variable to which the return value will subsequently be assigned.

Accordingly, you should always initialize function return values. This advice holds not only for strings, but for all data types.

This issue was discussed just yesterday here on Stack Overflow:

Do I need to setLength a dynamic array on initialization?

Leave a Comment