Board index » delphi » what about 'result'

what about 'result'

Hi,

is the use of 'result' in a function or procedure only for the 'beauty' of
the code or are there any advantages in compiling or running???

Regards
Adolf

 

Re:what about 'result'


Quote
a...@flunder.baltic.de (Adolf Raab) wrote:
>Hi,

>is the use of 'result' in a function or procedure only for the 'beauty' of
>the code or are there any advantages in compiling or running???

        Well, you could try it. If I change a project's source code by
changing a "result:=whatever" to "functionName:=whatever" the resulting
exe's are identical.

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Re:what about 'result'


Quote
In article <3...@flunder.baltic.de>, a...@flunder.baltic.de (Adolf Raab) wrote:
>Hi,

>is the use of 'result' in a function or procedure only for the 'beauty' of
>the code or are there any advantages in compiling or running???

There are a few advantages to using Result in a function (don't use it in a
procedure ;) :

* 'Result' is like having a temporary variable you can actually WORK with.  
The 'old' Pascal way would cause you to recurse if you said 'FunctionName :=
FunctionName+5' whereas 'Result := Result+5' increases what you set Result to
by five.

* Major side effects of the above are that you don't have to CREATE a
temporary variable to work with to get your result out.  GCC is one of the
few compilers other than Delphi I've seen with an option to use the space on
the stack for return values as a temporary (it lets you declare a 'return X;'
BEFORE the main body, and lets you use X with no extra cost, just like
Delphi's Result)

* You don't have to change your assignments when you change the name of your
function ;)

  --=- Ritchie A.

Other Threads