关于exe文件传递参数方法

段代码手工折叠

{$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

 

转载于:https://www.cnblogs.com/blogpro/p/11456938.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值