What is the default value of 'Result' in Delphi?

后端 未结 3 488
迷失自我
迷失自我 2020-11-27 21:24

Is there any guaranteed default value for the Result variable of a function, like 0, \'\' or nil? Or should Result always be initialised before use?

<
3条回答
  •  广开言路
    2020-11-27 21:50

    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?

提交回复
热议问题