How Can I Use Magic xpa User Functions in Magic xpi? (Magic xpi 4.6)
You can bring user-defined Magic xpa functions into your Magic xpi project. To do this, follow these steps.
In Magic xpi, follow these steps:
-
From the Project menu, select Settings. The Settings dialog box opens.
-
In the Settings dialog box's General Environment section, click User Environment Variables.
-
Make a note of the path set in this setting.
This setting can also be defined in the [MAGIC_LOGICAL_NAMES] section of Magic xpi’s Magic.ini file, which is located in the <Magic xpi installation>\Runtime\Magic xpa folder.
In Magic xpa, follow these steps:
-
Create a new project.
-
Create a user-defined function.
-
Create a cabinet file of this project making sure that the name is the same as the name defined in Magic xpi’s UserFunctionsLocation setting (as described above).
-
Save the file to the path defined in Magic xpi’s UserFunctionsLocation setting. For example: C:\Magic xpi 4.6\Runtime\User resources\UserFunctions.ecf
Back in Magic xpi, follow these steps:
-
Open the <Magic xpi installation>\Studio\FunctionDescription.xml file and add your function to the list with the relevant details, including the return type and parameters if required. You do this by copying an existing function, such as the one below, and editing the DisplayName, ReturnValue and Description tags, the <Parameters> section and any other relevant tags:
<Function>
<DisplayName>ABS</DisplayName>
<ReturnValue>N</ReturnValue>
<HideItem>N</HideItem>
<MinArgNum></MinArgNum>
<MaxArgNum></MaxArgNum>
<Obsolete></Obsolete>
<HelpID>9032</HelpID>
<FunctionSignature></FunctionSignature>
<Description>Returns the absolute value of a real number, without regard to sign.</Description>
<Parameters>
<Parameter>
<Name>number</Name>
<Type>N</Type>
<Description>Any number.</Description>
</Parameter>
</Parameters>
</Function>
-
Open the Studio and verify that your newly created function is available in the Expression Editor.
-
To be able to use the new function with the Data Mapper, you also need to add your function as an objectid in the comps.exp file. This is located in the <Magic xpi installation>\Runtime\Templates\Mapper folder. You do this by copying the text below to the file and updating the values of the Component name, the MciFile val tag, and the PublicName val tag:
Component name="UserFunction">
<CompId val="463816514-25434-19825-92354D96D"/>
<MciFile val="C:\Magic xpi 4.6\Runtime\Magic Xpa\Builders\ECI\userfunctions\UserFunction.eci"/>
<ComponentType val="Magic xpa"/>
<Type val="U"/>
<CABINET_FILE val="%UserFunctionsLocation%"/>
<LoadImmediate val="Y"/>
<CtlIndex val="6"/>
<LastISN val="1"/>
<ComponentFuncs>
<Object>
<id val="1"/>
<ItemIsn val="1"/>
<PublicName val="userfunctionsTest"/>
</Object>
</ComponentFuncs>