FireMonkeyアプリケーションでバージョン番号を取得する方法を紹介します。
使用したバージョンはDelphi 10 Seattleです。
バージョン番号を取得には、FMX.Platform.IFMXApplicationServiceのAppVersionプロパティを使用します。
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationService) then
begin
ApplicationService := IFMXApplicationService(TPlatformServices.Current.GetPlatformService(IFMXApplicationService));
Result := ApplicationService.AppVersion; //バージョン番号
end;
サンプルアプリケーションを作成します。
フォームにボタンを配置し、ボタンのOnClickイベントを追加します。
ボタンを押すと、バージョン番号を表示します。
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;
バージョンは、プロジェクトオプションの「バージョン情報」で設定できます。
アプリケーションを実行し、ボタンを押します。
バージョン番号が表示されました。