Re:How To: Command line args. eg pasprg arg1 arg2..argN??
Brendan Patrick Charles <bchar...@lawson.its.utas.edu.au> wrote:
Quote
> I am changing a pascal program and being a non-pascal person I have not
> been able to work out how to pass some variables from the command line
> and process them within the code. ie as in argv and argc in C.
> eg if pasprg is the name of the program then from the command line
> I want to type "pasprg 4 8 9" and have the 4,8 and 9 end up in variables
> so I can process them at runtime.
> I do not want to prompt for them with write/readln
> Any help and esp a small example would be greatly appreciated.
You can use ParamStr to pass the command line parameters to the program,
and use ParamCount for the number of parameters passed.
here's a short example:
Program Param_Example;
Var
ParamNum : Integer;
Begin
For ParamNum := 1 To ParamCount Do
WriteLn('Parameter ',ParamNum,': ',ParamStr(ParamNum));
End.
+---------------------+-------------------------+-----------------------------+
| Zulkarnain Shariff | z...@kmpssg.po.my |
+---------------------+-------------------------+-----------------------------+
| Computer Programmer | KOMPASS South-East Asia | Singapore |
+---------------------+-------------------------+-----------------------------+
+---------------------+-------------------------------------------------------+
| Zulkarnain Shariff | zu...@singnet.com.sg |
+---------------------+------------------------+------------------------------+
| Operations Manager | NetBase Computers (S) | Singapore |
| | SoftBase Computing (M) | Kuala Lumpur, Malaysia |
+---------------------+------------------------+------------------------------+
Standard_Disclamer:
The opinions expressed are strictly on my own, none of which reflects the
interest of the companies stated above, unless otherwise stated.