cObject
---cCommandLine
An object of cCommandLine is automatically instantiated within the program's cApplication object to encapsulate the values of the command-line that was passed to the running program by Windows. To access this object, use the cApplication's phoCommandLine property.
Two methods are used to access the command-line: CountOfArgs returns the number of arguments that were passed; you can obtain the value of any argument by using the Argument function, passing it the index of the argument that you want.
When passing a command-line to the program, you can pass an argument containing a space by enclosing it within quotes, as in this example:
C:\Program Files\DataFlex\Order\Programs\Order.exe Customer "ABC, Inc" Good No
This would result in the program receiving four arguments: (1) Customer (2) ABC, Inc (3) Good (4) No. Notice that the quote marks are removed when the argument is received.
In this example, the number of command-line arguments is displayed and then each argument is displayed.
Object oApplication is a cApplication Procedure OnCreate Handle hoCmdLine Integer iNumArgs iArg Get phoCommandLine To hoCmdLine Get CountOfArgs of hoCmdLine To iNumArgs Showln 'Number of command-line arguments=' iNumArgs For iArg from 1 to iNumArgs Showln 'Arg ' iArg ' :' (Argument(hoCmdLine, iArg)) Loop End_Procedure End_Object
Command line arguments are space- or comma-delimited strings that follow the name of the program. Arguments that contain spaces or commas themselves must be quoted.
This class supersedes use of the CmdLine command. A limitation of the CmdLine command is that once an argument was obtained, you could no longer gain access to it again as subsequent calls to CmdLine would return the next argument, etc. This class removes this limitation and ensures that you can access the command-line arguments as often as you desire and in any order. However, you can only use one of these options in your program. You can use either cCommandLine or CmdLine. To maintain compatibility with existing programs, this class will not "steal" the command-line, unless you specifically ask it to. That is, once you call either CountOfArgs or Argument, the class will take the contents of the command-line and store them internally. At this point, you will not be able to use the CmdLine in your program. Conversely, if you use CmdLine, then call either of these methods, they will not work (as CmdLine will have "stolen" the command-line.)
See Also