Mega Code Archive

 
Categories / Delphi / Examples
 

Multiple parameters in a command line

Title: Multiple parameters in a command line. Question: A suggestion to use the command line. Answer: In many occasions, emerges the need of manipulating the commands lines of voluminous or multiple way that is to say things as: Tester p1 fx k p p3 text.txt To pass external parameters to our programs. Here I offer a suggestion that will make of this work something much light. var I: Integer; Parameters: TStringList; begin Parameters := TStringList.Create; try for I := 1 to ParamCount do Parameters.Add(ParamStr(i)); If (Parameters.IndexOf (p1)-1) and (Parameters.IndexOf (p3)-1) Then //Your code here finally Parameters.Free; end; end; This code chunk can be used from the Creates you of a Form or from the beginning of an console application. NOTE. If you wish use this code from a console application, include CLASSES unit in then USES section. I know that exists the FindCmdLineSwitch, but here shown not alone can be used in the recognition of commands lines, maybe to help in other tasks as be: To order, to Modify, to Store commands in external files, the possibilities are many. I wait that could serve to you.