delphi中传参数才能运行的软件编写(ParamStr)

delphi中传参数才能运行的软件编写(ParamStr)

  • ParamStr
    表示的是启动应用程序时传给其的参数,比如在windows的dos系统下你想用命令符操作notepad.exe打开1.txt需要输入下面命令:c:\windows\system32\notepad.exe c:\1.txt
    c:\1.txt就是给notepad.exe传的参数。
  • ParamStr(0)
    代表应用程序名字,包括完整路径, 比如:C:\windows\system32\notepad.exe
  • ParamStr(1)……..ParamStr(n)
  • 就是传运行程序需要的参数,例如路径,打开方式等等。

在delphi的工程里的viewsource文件里加上 if system.ParamCount < 1 then
exit;
if not DirectoryExists(System.ParamStr(1)) then
exit;

这款软件运行时必须要传参数,而且参数是一个已经存在的路径,如果不存在,软件无法运行。有人会问参数怎么传进去,你可以先用dos的命令操作符试试,假如这款软件叫search.exe,路径在c盘根目录,那么你就可以这么写 C:\search.exe d:\;这里的d:\为路径参数,如果路径中有空格需要带双引号。

举例代码块

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  if system.ParamCount < 1 then
    exit;
  if not DirectoryExists(System.ParamStr(1)) then
      exit;

  Application.CreateForm(TDM, DM);
  Application.CreateForm(TFormSystemTree, FormSystemTree);
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值