Passing command line arguments to an Aion application
You can pass command line arguments to an Aion application by creating a _TaskInitialize method in the Entry class of the application and then adding a string input argument to this method. The command line arguments will be passed into this string input argument.
For example, let's say you have an Aion application that connects to a database and you want the application users to pass in their database userid and password with arguments /U and /P. To do this,you might have your _Taskinitialize method (in your Main class) as follows:
Method: _Taskinitialize
Arguments:
IN cmdline is stringMethod Body:
// extract userid
var loc1, loc2 integer
loc1 =index(cmdline,"/U")
if loc1 > 0 then
// findwhere argument ends (at a space)
loc2 =index(cmdline," ",loc1)
if (loc2 = 0)then
loc2 = length(cmdline) +1
end
loc1 = loc1+2
// get the userid
UserID =substring(cmdline,loc1,loc2-loc1)
else
UserID =NULL
end// extract Password
loc1 = index(cmdline,"/P")
if loc1 >0 then
// find where argument ends (at aspace)
loc2 = index(cmdline,"",loc1)
if (loc2 = 0) then
loc2 =length(cmdline) + 1
end
loc1 = loc1+2
// get thepassword
PassWord =substring(cmdline,loc1,loc2-loc1)
else
PassWord =NULL
end
The users can pass in the arguments by adding them to the shortcut used to invoke the application (e.g. if the build application is Loan.exe, the shortcut might be something like "c:\apps\loan.exe /Uscott /Ptiger").
You can test passing the arguments when running the application interpretively by either:
Please also note, that the command line is passed to EVERY library that has a _TaskInitialize defined in its entry class, not just to theapplication library. For example, if you have Loan.App which includesLoanRule.app, you can check one of the classes in LoanRule.App to be the Entry class then add an _TaskInitialize method to this class with a string input argument and this method (as well as the _TaskInitialize in Loan.AppMain._TaskInitialize) will also receive the command line input.
More general information on the _TaskInitializemethod
This method is for more than just getting command line arguments. _TaskInitialize can also be used to do one time"initialization" tasks for a library (as the name so aptly implies).When any Aion library is loaded (whether it's the main application, an included library, or a library component of another program), if there is a _TaskInitialize method in the entry class, it will be executed first.
A common use of _TaskInitialize:
If you want to initialize some attributes by reading values from the registry as the application loads, the _TaskInitialize method is a good approach to use. See the _Task._TaskInitialize method in Syslib for an example. Also, when the application is finished, the_TaskTerminate methods (if they exist) in the entry class of the library will be executed. This is a good place to put any last minute or "cleanup" logic (eg. saving settings to the registry).