Is Result variable defined from first line in a function?

后端 未结 3 1318
清歌不尽
清歌不尽 2021-01-12 01:34

I need a clarification of this case.

According my tests the Result variable is defined to: Boolean=False, Integer=0, String=\'\', Object=nil etc from the first line.

3条回答
  •  暖寄归人
    2021-01-12 02:01

    No, Result has no (guaranteed) default value. It is undefined unless you give it a value. This is implied by the documentation, which states

    If the function exits without assigning a value to Result or the function name, then the function's return value is undefined.

    I just tried

    function test: integer;
    begin
      ShowMessage(IntToStr(result));
    end;
    

    and got a message with the text 35531136.

提交回复
热议问题