Board index » delphi » Need Help with parameters In TurboPascal 7.0

Need Help with parameters In TurboPascal 7.0

Quote
Reidar Johansen <reid...@powertech.no> wrote:
>How can I, in a smart way, detect different parameters
>given from the command line. For instance, I want the user
>to be able to write MYPROGRAM followed by /? or -? or /H
>or /h or -H or -h to get help. I also want to use parameters
>like /I:12 or /I12 or /i:12 or -I:12 or -i:12 or -I12 or -i12
>for information screen number 12 and so on.
>I want the parameter /I:12 to be separated so that 12 or
>whatever comes after /I: (or just /I) can be put into a new
>variable. It's aslo important that many parameters can be
>given, and that the order does not matter. For instance
>MYPROGRAM /? /I:12 or MYPROGRAM /I:12 /? should have the
>same meaning.
>If there is someone out there that can help me (and want to
>help me), I would be very grateful to receive an email.
>--
>Reidar Johansen
>From Norway        ;-)         email: reid...@powertech.no

Use Paramstr and ParamCount. ParamCount returns the number of
parameters following the command line (everything separated by a
space). ParamStr (1) will return the first entry; ParamStr (2) the
second, and so on.

To process the slashes, you will have to write a little code to
examing the string after it has been retrieved.

 

Re:Need Help with parameters In TurboPascal 7.0


Hello All!

 JH> Reidar Johansen <reid...@powertech.no> wrote:

 >> How can I, in a smart way, detect different parameters
 >> given from the command line. For instance, I want the user
 >> to be able to write MYPROGRAM followed by /? or -? or /H
 >> or /h or -H or -h to get help. I also want to use parameters
 >> like /I:12 or /I12 or /i:12 or -I:12 or -i:12 or -I12 or -i12
 >> for information screen number 12 and so on.
 >> I want the parameter /I:12 to be separated so that 12 or
 >> whatever comes after /I: (or just /I) can be put into a new
 >> variable. It's aslo important that many parameters can be
 >> given, and that the order does not matter. For instance
 >> MYPROGRAM /? /I:12 or MYPROGRAM /I:12 /? should have the
 >> same meaning.

 >> If there is someone out there that can help me (and want to
 >> help me), I would be very grateful to receive an email.

To accomplish something like
    /?, inputfilename outputfilename /NOLOG /NOSCREEN
I would do something like this:

PROCEDURE Parameters;
VAR
  p,y               : BYTE
  Par               : STRING;
BEGIN
  Infn:='';
  Oufn:='';
  UseLog:=TRUE;
  UseScreen:=TRUE;
  FOR t:=1 TO PARAMCOUNT DO
  BEGIN
    Par:=PARAMSTR(t);
    FOR y:=1 TO LENGTH(Par) DO  Par[y]:=Par[y];
(* First look for / parameters, then other parameters*)
{ Help screen}
    IF (POS('?',Par)>0) THEN {If you require wildcards, use                  
COPY(Par,1,2)='/?')}
    BEGIN
      HelpScreen;
      HALT;
    END
{No logging}
    ELSE IF (POS('/NOLOG',Par)>0) THEN
      UseLog:=NOT UseLog {Makes for flipping the value if several /NOLOGs are
used}
{No screen output}
    ELSE IF (POS('/NOSCREEN',Par)>0) THEN
      UseScreen:=NOT UseScreen {Makes for flipping the value if several      
/NOSCREENs are used}
{Inputfilename}
    ELSE IF (Infn='') THEN
      Infn:=Par
{Outputfilename}
    ELSE IF (Infn<>'') AND (Oufn='') THEN
      Oufn:=Par;
  END;
  IF (Infn='') THEN Infn:='DEFAULT.FN';
END;

This you do not need to specify anything but the filenames to use, as all other
parameters are cut off first as they must have the / char before the value.
You could also segment the parameter check into two parts.
IF (Par[1] in ['/','-']) then
BEGIN
END
ELSE {other parameters}
BEGIN
END;

Hope this was any help

Regards
Mikkel Breiler Cosysop Renoz BBS, Vinyl/Intuition

Other Threads