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);