红鱼儿

使用FindCmdLineSwitch处理命令行参数

一、四个形式(变体)

1function FindCmdLineSwitch(const Switch: string; const Chars: TSysCharSet; IgnoreCase: Boolean): Boolean; overload;
2function FindCmdLineSwitch(const Switch: string): Boolean; overload;
3function FindCmdLineSwitch(const Switch: string; IgnoreCase: Boolean): Boolean; overload;
4function FindCmdLineSwitch(const Switch: string; var Value: string; IgnoreCase: Boolean = True;
  const SwitchTypes: TCmdLineSwitchTypes = [clstValueNextParam, clstValueAppended]): Boolean; overload;

二、函数功能
1、FindCmdLineSwitch 在应用程序内部判断指定的命令行参数是否存在,如果调用当前进程的命令行参数中包含了Switch参数指定的字符串, 函数返回值True,否则返回False

三、参数功能
1、Switch 指定命令行参数
2、Chars  指出哪个字符为命令分隔符(通常是-/)。
             SwitchChars = ['/','-']; // Windows下默认 
             SwitchChars = ['-'];     // Linux  下默认 
3、IgnoreCase 参数是否忽略大小写,True:忽略;False:不忽略
 
四、实例
1、Exanple.exe程序,通过Dos命令调用它时: Exanple.exe -AAA
2、在Exanple.exe程序,
   (1)调用Exanple.exe -AAA,FindCmdLineSwitch('AAA')=True;
   (2)调用Exanple.exe -BBB,FindCmdLineSwitch('AAA')=False;

五、Install

function Install: Boolean;
begin
  Result := FindCmdLineSwitch('INSTALL',['-','\','/'], True) or
            FindCmdLineSwitch('UNINSTALL',['-','\','/'], True);
end;

该函数功能:调用程序的Dos命令行中有“INSTALL”或“UNINSTALL”字符(命令行)时,(忽略大小写)返回真。

六、FindCmdLineSwitch所在单元

System.SysUtils

七、参考地址:

http://bbs.csdn.net/topics/391070266

 八、Delphi 版本:Delphi 10.3.2

 

posted on 2019-10-08 15:42  红鱼儿  阅读(677)  评论(0编辑  收藏  举报