Returns a specified parameter from the command-line.
function ParamStr(Index: Integer): string;
AnsiString ParamStr(int Index);
ParamStr returns the parameter from the command line that corresponds to Index, or an empty string if Index is greater than ParamCount. For example, an Index value of 2 returns the second command-line parameter.
C++ Examples:
/* The following example beeps once for each "beep" passed in on the command line. The example terminates the application if "exit" is passed in on the command line. Build the project to generate a .exe file and then execute that file from a command line: "ParamCount_proj beep beep exit". */ void __fastcall TForm1::FormCreate(TObject *Sender) { // Use print statements since you can't use the debugger. // MessageDlg( // "System ParamStr = " + AnsiString(System::ParamStr(i)), // mtConfirmation, TMsgDlgButtons() << mbOK, 0); for (int i=1;i<=ParamCount();i++) { if (LowerCase(ParamStr(i)) == "beep") Beep(); else if (LowerCase(ParamStr(i)) == "exit") Application->Terminate(); } }
Delphi Examples:
{ The following example beeps once for each "beep" passed in on the command line. The example terminates the application if "exit" is passed in on the command line. Build the project to generate a .exe file and then execute that file from a command line: "ParamCount_proj beep beep exit". } procedure TForm1.FormCreate(Sender: TObject); var i: Integer; begin // Use print statements since you can't use the debugger. // MessageDlg( // 'System ParamCount = ' + IntToStr(System.ParamCount), // mtConfirmation, [mbOK], 0); for i := 1 to System.ParamCount do begin if LowerCase(ParamStr(i)) = 'beep' then Beep else if LowerCase(ParamStr(i)) = 'exit' then Application.Terminate; Sleep(250); end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|