Board index » delphi » Command Line Args

Command Line Args

Quote
Daniel Gothe wrote:

> Hi,

> I've been programming TP for quite a while, but I've never done a program
> that requires command line args. However, when i recently wanted to have the
> possibility of using args.

> That's when I realized I didn't know how to do it! :)

> I looked through all my books, but despite recollecting that I've seen it at
> some point, I couldn't find any information about it.

> I would appreciate any information on writing programs with command line
> options. Preferably, I would want the args to be optional, making it
> possible to start a program without the args.

Using command-line arguments in a pascal program is very straight
forward.  The function paramcount returns a word containing the number
of command-line parameters.  The function paramstr returns a string
containing the specified parameter.  Say you have a program named
test.  Running the program as `test one two three`, paramstr (1) will
return 'one', paramstr (2) will return 'two', paramstr (3) will return
'three'.  IIRC paramstr (0) will return the name of the executable
under DOS versions > 3.3.

--
----------------------------------------------------------------------
Phil Brutsche

"Be of stout heart, Number One.  We've handled the Borg.  We can
certainly handle Admiral Jellico." - Jean-Luc Picard

----------------------------------------------------------------------

 

Re:Command Line Args


Hi,

I've been programming TP for quite a while, but I've never done a program
that requires command line args. However, when i recently wanted to have the
possibility of using args.

That's when I realized I didn't know how to do it! :)

I looked through all my books, but despite recollecting that I've seen it at
some point, I couldn't find any information about it.

I would appreciate any information on writing programs with command line
options. Preferably, I would want the args to be optional, making it
possible to start a program without the args.

Thanks,

Daniel, Sweden

(TO REPLY BY EMAIL, DELETE THE REMOVE FROM MY EMAIL ADDRESS)

Re:Command Line Args


Look in TP help or your favorite manual for ParamStr and
ParamCount.  Also, you could take a look at GetEnv.....

Quote
Daniel Gothe wrote:

> Hi,

> I've been programming TP for quite a while, but I've never done a program
> that requires command line args. However, when i recently wanted to have the
> possibility of using args.

> That's when I realized I didn't know how to do it! :)

> I looked through all my books, but despite recollecting that I've seen it at
> some point, I couldn't find any information about it.

> I would appreciate any information on writing programs with command line
> options. Preferably, I would want the args to be optional, making it
> possible to start a program without the args.

> Thanks,

> Daniel, Sweden

> (TO REPLY BY EMAIL, DELETE THE REMOVE FROM MY EMAIL ADDRESS)

Re:Command Line Args


Yeap... it's easy....

Look up ParamCount and ParamStr in TP's help...

ParamCount returns the number of parameters passed.
ParamStr passes each parameter.

They do not require any TPU's.

Have fun...

Erez Steinberg,
ere...@ibm.net

Quote
Daniel Gothe wrote:
> I would appreciate any information on writing programs with command
> line
> options. Preferably, I would want the args to be optional, making it
> possible to start a program without the args.

Other Threads