블로그 이미지
훅크선장

카테고리

분류 전체보기 (362)
사진이야기 (23)
펭귄컴퓨팅 (121)
컴퓨터보안 (84)
절름발이 프로그래머 (59)
하드웨어개조 (23)
멀알려줄까 (35)
홈베이킹&홈쿠킹 (2)
잡다한것들 (15)
Total
Today
Yesterday

달력

« » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

공지사항

태그목록

최근에 올라온 글

ParamCount 와 ParamStr 을 이용하여, 명령어 인자를 처리할 수 있다.

Form이 있건, 없건 상관이 없다.

Console Program의 경우에 대해서, 다음과 같이 소스로 만들면 된다.
Form이 있는 프로그램인 경우에는, 아래 소스를 발췌하여, FormCreate() 함수에 추가하면 된다.

인자 사용법은 실행시에,
c:>  Project1.exe  -a:HERE_IS_A  -b:THRER_IS_B
와 같이 씁니다.

아래소스에는 반드시 FastStrings 모듈을 추가해서 사용해야 합니다.

--------------------------------------------------------------------------------
program Project1;

{$APPTYPE CONSOLE}

uses
  Sysutils,
  Classes,
  Dialogs,
  FastStringFuncs in 'src\FastStringFuncs.pas',
  FastStrings in 'src\FastStrings.pas';

var
   param_idx:integer;
   argumentstr, prefix, realarg : String;
   arguments : TStrings;

begin
  try
    { TODO -oUser -cConsole Main : Insert code here }
     for param_idx := 1 to ParamCount do
   begin
     //ShowMessage(ParamStr(param_idx));
     argumentstr := ParamStr(param_idx);
     if (argumentstr[1] = '-') then
     begin
       Split(Copy(argumentstr, 2, Length(argumentstr) - 1), ':', arguments);
       prefix := arguments[0];
       realarg := arguments[1];
       if ((arguments.Count = 2) and (Length(prefix) = 1)) then
       begin
         Case arguments[0][1] of
            'a' : ShowMessage( 'option a : ' + arguments[1]);
            'b' : ShowMessage( 'option b : ' + arguments[1]);
         else ;
         end;
       end;
     end;

   end;

  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.
Posted by 훅크선장
, |