Parameters that Can be Passed to Global Functions
Description
You can pass any Alpha Anywhere variable type to a Global Function. This includes variables of type:
C (character)
D (date)
N (numeric)
L (logical)
T (time)
B (blob - binary large object)
P (pointer)
U (collection)
F (function) -the name of another global function.
Passing in a function name is useful when you want to create a function that uses a different function internally depending on a parameter that was passed to it. For example:
function get_left as C (string as C, length as N)
Get_left = left(string,length)
end function
function get_right as C (string as C, length as N)
Get_right = right(string,length)
end function
function get_string as C (string as C, length as N, function as f)
Get_string = function(string,length)
end functionIf you called this function using the command, get_string("now is the time,3, get_left), it would return the left most 3 characters of the string, (using the user-defined get_left() function).
? get_string("now is the time",3,get_right)If you want to pass in a variable whose type you do not know in advance, you can pass the variable using the "as A" declaration. Then, in the body of your function, you can test the variable's type.
function what_type as C (input as a)
What_type = typeof(input)
end functionUse the pointer type when you want to pass in multiple variables at once, and return multiple variables. For example:
function adjust as P (who as P)
Who.firstname= upper(who.firstname)
Who.lastname = upper(who.lastname)
Who.salary = who.salary*1.1
Adjust = who
end functionNow, test out the function :
dim person as P Person.firstname = "Fred" Person.lastname = "Thomas" Person.salary = 35500 X = adjust(person) ? x.salary = 39050.000000 ? person.salary = 39050.000000
To reference an array in a function, use the pointer type. For example:
function capitalize as P (input_array as P)
Size = input_array.size()
For I = 1 to size
Input_arrayI = upper(input_arrayI )
Next it
Capitalize = input_array
end functionNow, test out the function :
dim cities5 as C Cities.initialize(<<%a% Boston New york Los angeles London Madrid %a%) capitalize(cities) ? cities = 1 = "BOSTON" 2 = "NEW YORK" 3 = "LOS ANGELES" 4 = "LONDON" 5 = "MADRID"
See Also