在 fire monkey (FMX) 中检索 Delphi 运行时应用程序版本和 OSX 的应用程序构建信息

Retrieve Delphi runtime application version and application build information for OSX in fire monkey (FMX)

我试图找到一个关于如何检索应用程序版本和构建 nr 的示例,以便我可以在 OSX 应用程序的帮助框中显示它。

在 Windows 上是微不足道的,但在 Mac 上却不是。

希望能帮到你!

爱德华

我使用我编写的这段代码。只需致电:

osxNSBundle.BundleVersion()

代码如下:

uses
  Macapi.Foundation,
  Macapi.Helpers;

osxNSBundle = class
private
  class function MainBundle: NSBundle;
public
  class function BundlePath: string;
  class function BundleVersionStr: string;
  class procedure BundleVersion(var aMajor,aMinor,aBuild: integer);
end;

implementation

class function osxNSBundle.MainBundle: NSBundle;
begin
  result := TNSBundle.Wrap(TNSBundle.OCClass.mainBundle);
end;

class function osxNSBundle.BundlePath: string;
begin
  result := NSStrToStr(MainBundle.bundlePath);
end;

class function osxNSBundle.BundleVersionStr: string;
begin
  Result := NSStrToStr(TNSString.Wrap(MainBundle.objectForInfoDictionaryKey(StrToNSStr('CFBundleVersion'))));
end;

class procedure osxNSBundle.BundleVersion(var aMajor,aMinor,aBuild: integer);
var lStrArray: TArray<string>;
i: Integer;
begin
  aMajor := 0; aMinor := 0; aBuild := 0;
  lStrArray := BundleVersionStr.Split(['.']);
  if Length(lStrArray)>=3 then
  begin
    aMajor := lStrArray[0].ToInteger;
    aMinor := lStrArray[1].ToInteger;
    aBuild := lStrArray[2].ToInteger;
  end;
end;