Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Loading a Delphi program with Posted by pascal-coder on 10 Aug 2006 at 12:37 PM
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 :)
Report
Re: Loading a Delphi program with Posted by zibadian on 10 Aug 2006 at 1:58 PM
: 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.
Report
Re: Loading a Delphi program with Posted by pascal-coder on 10 Aug 2006 at 2:16 PM
: : 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 :)
Report
Re: Loading a Delphi program with Posted by porodoro on 12 Aug 2006 at 10:48 AM
: : : 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 ?

Report
Re: Loading a Delphi program with Posted by zibadian on 12 Aug 2006 at 12:05 PM
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

Report
Re: Loading a Delphi program with Posted by porodoro on 13 Aug 2006 at 8:01 AM
: 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 :)




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.