Procedures

Prior | Next

Calling Procedures and Functions
Procedures and functions are modular pieces of code that perform some specific task.  They are known as subroutines in other languages.  The ESPL library contains more than 300 powerful procedures and functions that serve as building blocks for use in your scripts.  While you don't need to understand the logic of the code within the ESPL procedures and functions, you need to understand what they do.  When procedures and functions are declared within objects like a TStringList, they are called methods.

Of course, you can create your own procedures and functions in your script.  Use them to divide the logic of your application into manageable chunks.  If a block of code has more than 25 lines, it is a candidate for being divided into more manageable chunks.

To Use an Existing Procedure
Type the name of the procedure as a statement in your code.  This is called "calling a procedure."

For example, the TStringList object has a Sort method. Because this functionality is built into the object, you need to know only what the method does and how to use it. This is how you call the Sort method of a TStringList object named sList:

  sList.Sort;

Note that the name of the object, sList, is part of the method call. By including the name of the object, you are specifying which string list you want to sort. Separate the name of the object from the method call with a period.  If you omit the name of the control, component, or object in a method call, ESPL usually displays this syntax error:

  Unknown Identifier

Passing Parameters
Many procedures and functions require you to specify parameters.  The statements of the called procedure use the values passed in the parameters when the procedure's code runs.  The values are treated as variables declared within the procedure. Parameters are surrounded with parentheses in a procedure call.  For example, the LoadFromFile method is declared in a TStringList object like this:

  procedure LoadFromFile(sFileName: string);

sFileName, the sole parameter of the method, is of type String.  When you call the LoadFromFile method, you specify which file you want loaded by specifying a string as the sFileName parameter.  This code would read the MYFILE.TXT file into a string list named sList:

  sList.LoadFromFile( 'MyFile.txt' );

Prior | Next