码迷,mamicode.com
首页 > 其他好文 > 详细

关于exe文件传递参数方法

时间:2019-09-04 09:40:11      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:pie   arguments   lan   for   nat   array   str   传递参数   bee   

段代码手工折叠

{$REGION ‘Designer Managed Code‘}
............
{$ENDREGION}

昨天同事问到,delphi里exe文件如何传递参数?

因为手头装了Delphi,PowerBuilder

以下就是代码:

Delphi:

技术图片
procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i:=1 to ParamCount  do
  begin
    if LowerCase(ParamStr(i)) = beep then
      Application.MessageBox(Demo,beep,IDOK )
   else if LowerCase(ParamStr(i))=exit then
      Application.Terminate;       
  end;
end;
View Code

PowerBuilder:

技术图片
string ls_cmd, ls_arg[]

integer i, li_argcnt

// Get the arguments and strip blanks
// from start and end of string
ls_cmd = Trim(CommandParm())

li_argcnt = 1
DO WHILE Len(ls_cmd) > 0

// Find the first blank
i = Pos( ls_cmd, " ")

// If no blanks (only one argument),
// set i to point to the hypothetical character
// after the end of the string
if i = 0 then i = Len(ls_cmd) + 1

// Assign the arg to the argument array.
// Number of chars copied is one less than the
// position of the space found with Pos
ls_arg[li_argcnt] = Left(ls_cmd, i - 1)

// Increment the argument count for the next loop
li_argcnt = li_argcnt + 1

// Remove the argument from the string
// so the next argument becomes first
ls_cmd = Replace(ls_cmd, 1, i, "")

LOOP
View Code

使用:

*.exe beep exit

技术图片

 

关于exe文件传递参数方法

标签:pie   arguments   lan   for   nat   array   str   传递参数   bee   

原文地址:https://www.cnblogs.com/blogpro/p/11456938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!