:
This message was edited by zibadian at 2006-8-12 12:9:57
: : : : : Hello there,
: : : : : I have a question. Im sure it is possible but I just don't know how to do it. Is it possible to load a DP program from the CMD ( or a .BAT file) with userdata ( 'test.exe Hi there' or 'test.exe -y' and use this userdata in the application?
: : : : : For example :
: : : : : X is Userdata so If I call test.exe like this 'test.exe Hello World' X would be 'Hello World' a string which I will then use in my application.
: : : : :
: : : : : Thanks for every help I recieve on this :)
: : : : :
: : : : That's possible. Delphi has 2 functions which allows you to get the command line parameters: ParamCount() and ParamStr(). The former gives you the number of parameters, while the latter returns a single parameter based on the function parameter. Example:
: : : :
: : : : Label1.Caption := '';
: : : : if ParamCount > 0 then
: : : : for i := 1 to ParamCount do
: : : : Label1.Caption := Label1.Caption + ParamStr(i) + ' ';
: : : :
: : : : This example fills a label with all the commandline parameters.
: : : :
: : :
: : : Thanks that really helped :)
: : :
: : Hmm , may i ask a question based on pascal-coder's question?
: : How do you read more than one parameter without using copy/pos etc string functions ?
: :
: :
: ParamStr(i) returns the i-th command line parameter. If you want to have only the 2nd and 3rd parameter, use this code:
:
: if ParamCount > 2 then begin
: Label1.Caption := ParamStr(2);
: Label2.Caption := ParamStr(3);
: end;
:
: The returned values are always strings, so you might need to convert them to the types you need.
: You can also call them as many times as you like:
:
: if ParamCount > 0 then
: for i := 0 to 99 do
: Memo1.Lines.Add(ParamStr(1)); // Show 100 times 1st parameter
:
:
Perfect , thanks zibadian :)