Q&A

  • application자신의 버전을 동적으로 참조하는 방법
프로젝트 옵션에 가보면..메이저, 마이너, 릴리즈, 빌드의 4가지 버전이 나오잖아요..

실행시 이 값을 참조하여 about창에 버전을 display하고싶습니다.

방법을 알려주세요.

-locke
1  COMMENTS
  • Profile
    박상기 2002.11.03 05:51

    function getVersion : string;
    { ---------------------------------------------------------
       Extracts the FileVersion element of the VERSIONINFO
       structure that Delphi maintains as part of a project's
       options.

       Results are returned as a standard string.  Failure
       is reported as "".

       Note that this implementation was derived from similar
       code used by Delphi to validate ComCtl32.dll.  For
       details, see COMCTRLS.PAS, line 3541.
      -------------------------------------------------------- }
    const
       NOVIDATA = '';

    var
      dwInfoSize,           // Size of VERSIONINFO structure
      dwVerSize,            // Size of Version Info Data
      dwWnd: DWORD;         // Handle for the size call.
      FI: PVSFixedFileInfo; // Delphi structure; see WINDOWS.PAS
      ptrVerBuf: Pointer;   // pointer to a version buffer
      strFileName,          // Name of the file to check
      strVersion : string;  // Holds parsed version number
    begin

       strFileName := paramStr( 0 );
       dwInfoSize :=
          getFileVersionInfoSize( pChar( strFileName ), dwWnd);

       if ( dwInfoSize = 0 ) then
          result := NOVIDATA
       else
       begin

          getMem( ptrVerBuf, dwInfoSize );
          try

             if getFileVersionInfo( pChar( strFileName ),
                dwWnd, dwInfoSize, ptrVerBuf ) then

                if verQueryValue( ptrVerBuf, '',
                                  pointer(FI), dwVerSize ) then

                strVersion :=
                   format( '%d.%d.%d.%d',
                           [ hiWord( FI.dwFileVersionMS ),
                             loWord( FI.dwFileVersionMS ),
                             hiWord( FI.dwFileVersionLS ),
                             loWord( FI.dwFileVersionLS ) ] );

          finally
            freeMem( ptrVerBuf );
          end;
        end;
      Result := strVersion;
    end;


    procedure TForm1.Button1Click(Sender: TObject);
    begin
    lblVersion.Caption := '버젼: ' + getVersion;

    end;

    end.