tranleduy2000 / pascalnide

Pascal Compiler for Android
91 stars 25 forks source link

[lang] Function result variabel doesn't work #8

Closed pakLebah closed 7 years ago

pakLebah commented 7 years ago

Today's Pascal —as being used by FPC and Delphi since ages ago— has result variable declared implicitly within a function. This doesn't work in Pascal N-IDE.

Example:

function f(p: integer): string;
// var result: string <-- implicitly added by the compiler
begin
  if p = 0 then
    result := 'zero'
  else
    result := intToStr(p);
end;

Because result is a variable, it acts like a variable. For example, if the function output is a dynamic array, the result size can be defined by setLength() procedure from within the function.

Reference: https://www.freepascal.org/docs-html/current/ref/refse90.html#x174-19600014.3

tranleduy2000 commented 7 years ago

I supported result variable, add {$MODE DELPHI} in the top of program. See commit 337d56184f8bd675542d500ffc8be9197b551dbc