Delphi 10 SeattleのFireMonkeyアプリケーションでバージョン番号を取得するには

FireMonkeyアプリケーションでバージョン番号を取得する方法を紹介します。

使用したバージョンはDelphi 10 Seattleです。

バージョン番号を取得には、FMX.Platform.IFMXApplicationServiceAppVersionプロパティを使用します。

  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationService) then
  begin
    ApplicationService := IFMXApplicationService(TPlatformServices.Current.GetPlatformService(IFMXApplicationService));
    Result := ApplicationService.AppVersion; //バージョン番号
  end;

サンプルアプリケーションを作成します。

フォームにボタンを配置し、ボタンのOnClickイベントを追加します。

01

ボタンを押すと、バージョン番号を表示します。

uses FMX.Platform;

/// <summary>
/// アプリケーションのバージョン番号を取得する
/// </summary>
function GetAppVersion: string;
var
  ApplicationService: IFMXApplicationService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationService)
  then
  begin
    ApplicationService := IFMXApplicationService
      (TPlatformServices.Current.GetPlatformService(IFMXApplicationService));
    Result := ApplicationService.AppVersion;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GetAppVersion);
end;

バージョンは、プロジェクトオプションの「バージョン情報」で設定できます。

02

アプリケーションを実行し、ボタンを押します。

2016-04-19-22-42-51

バージョン番号が表示されました。

2016-04-19-22-43-02

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください