Board index » delphi » Retrieving command line parameters in TP7 via CmdLine sysvar

Retrieving command line parameters in TP7 via CmdLine sysvar

I'm trying to get the parameters issued to my TP7 program via the system
variable CmdLine, but when I try to access it, I get the error "Error 3 -
Unknown Identifier" in any references to CmdLine.

It  should be  inside  the System Unit ...
Any ideas?.

Thanks.
Jesus.

 

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


Quote
> I'm trying to get the parameters issued to my TP7 program via the system
> variable CmdLine, but when I try to access it, I get the error "Error 3 -
> Unknown Identifier" in any references to CmdLine.
> It  should be  inside  the System Unit ...

   Sure.  Use ParamCount and ParamStr.

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


In article <01bcf433$d0efb0d0$6d646480@pc01077>, =?iso-
8859-1?q?Jes=FAs_Consuegra?= <jconsue...@redestb.es> writes

Quote
>I'm trying to get the parameters issued to my TP7 program via the system
>variable CmdLine, but when I try to access it, I get the error "Error 3 -
>Unknown Identifier" in any references to CmdLine.

>It  should be  inside  the System Unit ...
>Any ideas?.

You are wanting the paramstr functions within TP7 rather than cmdline.

If you want individual parameters then paramstr(x) will give you the x
parameter as a string. ParamCount holds the number of parameters given
on the command line to the program.

If you want to have all the parameters to your program in one string
then something like :

var ParString : string;
var i : byte;
begin
     parString := '';
     for i := 1 to ParamCount do ParString := ParString+' '+ParamStr(i);
end.

Will put all the command line parameters into one string with a space
between each parameter.
--
Pedt Scragg <postmas...@pedt.demon.co.uk>

In principle,   is there uncertainty that
Heisenberg was working his best in chaos?

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


In article <01bcf433$d0efb0d0$6d646480@pc01077>,

Quote
Jess Consuegra <jconsue...@redestb.es> wrote:
>I'm trying to get the parameters issued to my TP7 program via the system
>variable CmdLine, but when I try to access it, I get the error "Error 3 -
>Unknown Identifier" in any references to CmdLine.

You can get command line by following:

cdmline=^string;

cmdline:=ptr(prefixseg,128);

and then use cmdline^

Osmo

Quote

>It  should be  inside  the System Unit ...
>Any ideas?.

>Thanks.
>Jesus.

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


Jess Consuegra <jconsue...@redestb.es> wrote in article
<01bcf433$d0efb0d0$6d646480@pc01077>...

Quote
> I'm trying to get the parameters issued to my TP7 program via the system
> variable CmdLine, but when I try to access it, I get the error "Error 3 -
> Unknown Identifier" in any references to CmdLine.

> It  should be  inside  the System Unit ...
> Any ideas?.

> Thanks.
> Jesus.

Wow, another system variable I didn't know about!

Tried compiling Begin Writeln(CmdLine); End. and it worked when the target
was Windows but not when it was Real or Protected mode. So it looks like a
windows-only feature.

In DOS you'll have to use the string variable at prefixseg:$80, but be sure
to copy it somewhere more permanent early in the program.

Type pString = ^String; { you probably have this already }
Var CmdLine : String; { confusing variable name }
Begin
  CmdLine := pString(Ptr(PrefixSeg, $80))^;
  ... rest of program ...
End.

That works in real & protected modes

Frank

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


Thanks to Osmo and Pedt. That was I needed.
Jesus.

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


In article <01bcf433$d0efb0d0$6d646480@pc01077> of Tue, 18 Nov 1997
15:08:51 in comp.lang.pascal.borland, =?iso-8859-1?q?Jes=FAs_Consuegra?=

Quote
<jconsue...@redestb.es> wrote:
>I'm trying to get the parameters issued to my TP7 program via the system
>variable CmdLine, but when I try to access it, I get the error "Error 3 -
>Unknown Identifier" in any references to CmdLine.

Consider   URL: http://www.merlyn.demon.co.uk/pas-norm.htm#CLPars

--
John Stockton, Surrey, UK.    j...@merlyn.demon.co.uk    Turnpike v1.12    MIME.
  Web URL: http://www.merlyn.demon.co.uk/ - FAQqish topics, acronyms and links.
  Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
  Before a reply, quote with ">" / "> ", known to good news readers (SoRFC1036)

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


In article <5TvSPIANphc0E...@pedt.demon.co.uk>,
Pedt Scragg  <postmas...@pedt.demon.co.uk> wrote:

Quote

>If you want to have all the parameters to your program in one string
>then something like :

>var ParString : string;
>var i : byte;
>begin
>     parString := '';
>     for i := 1 to ParamCount do ParString := ParString+' '+ParamStr(i);
>end.

>Will put all the command line parameters into one string with a space
>between each parameter.

So if I were to write a search filter and I used it search strings with
four spaces, like:

Find "    " *.*

How would your solution work?

If one needs the command line one needs the command line and not some
recollection from already prepared data.

Osmo

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


In article <01bcf47e$9c229520$LocalHost@fp>,

Quote
Frank Peelo <fpe...@indigo.ie> wrote:

>Tried compiling Begin Writeln(CmdLine); End. and it worked when the target
>was Windows but not when it was Real or Protected mode. So it looks like a
>windows-only feature.

>In DOS you'll have to use the string variable at prefixseg:$80, but be sure
>to copy it somewhere more permanent early in the program.

There is no need whatsoever to copy it anywhere. In fact paramstr and
paramcount inspect the same area every time they are called. So if you
trust paramstr you should trust the command line.

The feature that paramcount and paramstr inspect the area can be sued to
split arbitrary string into words by writing that string into the
command line area (remember to restore the original one after doing that.

Osmo

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


 126643 Nov 14 1997 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

18. *****
 Q: How can I obtain the entire command line (spaces and all)?

 A: ParamCount and ParamStr are for parsed parts of the command line
and cannot be used to get the command line exactly as it was. See
what happens if you try to capture
  "Hello.   I'm here"
you'll end up with a false number of blanks. For obtaining the
command line unaltered use
  type CommandLineType = string[127];
  var  CommandLinePtr  : ^CommandLineType;
  begin
    CommandLinePtr := Ptr(PrefixSeg, $80);
    writeln (CommandLinePtr^);
  end;
A warning. If you want to get this correct (the same goes for TP's
own ParamStr and ParamCount) apply them early in your program. At
least they must be used before any disk I/O takes place!
:
A related example demonstrating a function giving the number of
characters on the command line
  function CMDNBRFN : byte;
  var paramPtr : ^byte;
  begin
    paramPtr := Ptr (PrefixSeg, $80);
    cmdnbrfn := paramPtr^
  end;  (* cmdnbrfn *)
For the contents of the Program Segment Prefix (PSP) see Tischer,
Michael (1992), PC Intern System Programming, p. 753.
--------------------------------------------------------------------

   All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland

Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


In article <656043$...@majakka.uwasa.fi>,

Quote
Timo Salmi <t...@majakka.uwasa.fi> wrote:
>A warning. If you want to get this correct (the same goes for TP's
>own ParamStr and ParamCount) apply them early in your program. At
>least they must be used before any disk I/O takes place!
>:

This must be a joke. One should not generalize principles learned from
low level languages like Assembler to HLL like Pascal.

Osmo

Re:Retrieving command line parameters in TP7 via CmdLine sysvar


In article <656li3$...@kruuna.Helsinki.FI>,

Quote
Osmo Ronkanen <ronka...@cc.helsinki.fi> wrote:

:In article <656043$...@majakka.uwasa.fi>,
Quote
:Timo Salmi <t...@majakka.uwasa.fi> wrote:

:>A warning. If you want to get this correct (the same goes for TP's

:This must be a joke. One should not generalize principles learned from
:low level languages like Assembler to HLL like Pascal.

Osmo, don't worry. I would not dream of stooping to a low level in
my programming.

   All the best, Timo  (aka Perfesser Pundit in news:rec.humor)

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland

Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.

Other Threads