關於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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM