Exit with a Value

Traditionally Pascal functions used to assign a result by using the function name, as in:

function ComputeValue: Integer; begi n

ComputeValue := 10; end;

Delphi has long provided an alternative coding, using the Result identifier to assign a return value to a function:

function ComputeValue: Integer; begi n

The two approaches are identical and do not alter the flow of the code. If you need to assign the function result and stop the current execution you can to use two separate statements, assign the result and then call Exit. The following code snippet looking for a string containing a given number in a string list (part of the MinorLang example) shows a classic example of this approach:

function FindExit (sl: TStringList; n: Integer): string; var

I: Integer; begi n for I := 0 to sl.Count do if Pos (IntToStr (n), sl[I]) > 0 then begi n

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment