cfcomponent & cfscript
I found a UDF that is very useful for my web app. But the UDF is written in cfscript
I want to create a component and put this UDF inside since I'm sure in the future I will be using a lot of this function. So anytime I need this function I can just call using cfinvoke
Usually I use cfinvoke to call my component this way:
<cfinvoke component="#Location#" method="MyFunction" st_MyStuct ="#st_MyStuct#" MyList = "#MyList#">
Then in the CFComponent I have something like:
<cfcomponent
displayname="NameCheckSystem" hint="">
<CFFUNCTION
name="CheckAddresses">
<cfargument name="st_MyStruct" type="Structure" required="true">
<cfargument name="MyList" type="String" required="true">
.....etc
</CFFUNCTION>
</cfcomponent>
Since this UDF is written in cfscript, I'm not sure how is the right syntax to pass the arguments.
<cfcomponent
displayname="NameCheckSystem" hint="">
<!--- below is the original cfscript codes --->
<cfscript>
function ListUnion(List1, List2)
{
var TempList = "";
var CombinedList = "";
Var SortType="text";
Var SortOrder="asc";
var Delim1 = ",";
var Delim2 = ",";
var Delim3 = ",";
var i = 0;
// Handle optional arguments
switch(ArrayLen(arguments)) {
case 3:
{
Delim1 = Arguments[
3];
break;
}
case 4:
{
Delim1 = Arguments[
3];
Delim2 = Arguments[
4];
break;
}
case 5:
{
Delim1 = Arguments[
3];
Delim2 = Arguments[
4];
Delim3 = Arguments[
5];
break;
}
case 6:
{
Delim1 = Arguments[
3];
Delim2 = Arguments[
4];
Delim3 = Arguments[
5];
SortType = Arguments[
6];
break;
}
case 7:
{
Delim1 = Arguments[
3];
Delim2 = Arguments[
4];
Delim3 = Arguments[
5];
SortType = Arguments[
6];
SortOrder = Arguments[
7];
break;
}
}
// Combine list 1 and list 2 with the proper delimiter
CombinedList =
ListChangeDelims(List1, Delim3, Delim1) & Delim3 & ListChangeDelims(List2, Delim3, Delim2);
// Strip duplicates if indicated
for (i=1; i LTE ListLen(CombinedList, Delim3); i=i+1) {
if (NOT ListFindNoCase(TempList, ListGetAt(CombinedList, i, Delim3), Delim3)){
TempList =
ListAppend(TempList, ListGetAt(CombinedList, i, Delim3), Delim3);
}
}
Return ListSort(TempList, SortType, SortOrder, Delim3);
}
</cfscript>
</cfcomponent>
