Arguments
Username:  
Password:
  > Home
v User Guide
    > Introduction
    > Hello World
    > Flow Control
    v Function Calls
       o Arguments
       o Argument list
       o Absolute arguments
       o Results
       o Context linking
       o Pass by reference
    > Authentication
    > Database access
    > Content Management
    > Remote Calling
    > Object-Oriented
    > Other Features
> Reference
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> User Guide >> Function Calls >> Arguments <=  =>      <  1  >  
Arguments

Arguments on the function declaration line are for specifying default values only.  It is a good practice to assign a default value for every specific arguments.

In the function, you can detect the absence of an argument from the calling command by the "isset" conversion.  However, if you specify a default value (even a blank) on the function declaration line, you cannot detect the absence of such argument from the calling command as the "isset" of that argument will be always true.

Here is an example of using "isset" within a function.

function sayit {

   if ({arg%what|isset}) {

         if ('{arg%what}' != '') display 'You just said "{arg%what}"';

         else display 'Come on, say something';

   }

}

 

sayit what="Hi";  // Output: You just said "Hi"

sayit what="";    // Output: Come on, say something

sayit;            // No output

 

As a common rule, argument name same as the function name can be omitted.  (Same is true for system commands as well.)  So the above function can be changed to (please note the argument "what" has been changed to "sayit" within the function):

function sayit {

   if ({arg%sayit|isset}) {

         if ('{arg%sayit}' != '') display 'You just said "{arg%sayit}"';

         else display 'Come on, say something';

   }

}

 

sayit "Hi";  // Output: You just said "Hi"

sayit "";    // Output: Come on, say something

sayit;       // No output

 

Although the above example works, it is not a good programming practice to include the function name in the function code; it may cause problem if you change the function name (e.g. in copy-and-paste reuse) in the future.  There is a special argument that helps you do this – arg%function:function.  You can replace all reference to the function name with "{arg%function:function}". Look at this:

function sayit {

   if ({arg%{arg%function:function}|isset}) {

         if ('{arg%{arg%function:function}}' != '')

               display 'You just said "{arg%{arg%function:function}}"';

         else display 'Come on, say something';

   }

}

 

Now if you want to change the function name, the declaration line is all that needs to be changed.

 

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd