http://www.cnblogs.com/onechen/p/3627942.html

XE7 源码下载:[原创]取得APP自己的版本号(狠跨4个平台)XE7.zip

XE6 源码下载:[原创]取得APP自己的版本号(狠跨4个平台)XE6.zip

XE5 源码下载:[原创]取得APP自己的版本号(狠跨4个平台).zip

取得 APP 自己的版本号 (跨 4 个平台)-LMLPHP

取得 APP 自己的版本号 (跨 4 个平台)-LMLPHP
//------------------------------------------------------------------------------
// by [龟山]阿卍 QQ:1467948783
// http://www.cnblogs.com/onechen/
//------------------------------------------------------------------------------ unit Main; interface uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, {$IFDEF MSWINDOWS}
Winapi.Windows,
{$ENDIF} {$IFDEF ANDROID}
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes,
FMX.Helpers.Android,
Androidapi.Helpers, // XE7 需要引入
{$ENDIF}
  {$IFDEF IOS}
FMX.Platform.iOS,
iOSapi.Foundation,
Macapi.ObjectiveC,
{$ENDIF} {$IFDEF MACOS}
FMX.Platform.Mac,
Macapi.Foundation,
Macapi.ObjectiveC,
{$ENDIF} FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
FMX.Memo, FMX.StdCtrls; type
TForm1 = class(TForm)
ToolBar1: TToolBar;
Label1: TLabel;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx} {$IFDEF MSWINDOWS}
procedure GetBuildInfo(var V1, V2, V3, V4: word);
var
VerInfoSize, VerValueSize, Dummy: DWORD;
VerInfo: Pointer;
VerValue: PVSFixedFileInfo;
begin
VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
if VerInfoSize > 0 then
begin
GetMem(VerInfo, VerInfoSize);
try
if GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo) then
begin
VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
with VerValue^ do
begin
V1 := dwFileVersionMS shr 16;
V2 := dwFileVersionMS and $FFFF;
V3 := dwFileVersionLS shr 16;
V4 := dwFileVersionLS and $FFFF;
end;
end;
finally
FreeMem(VerInfo, VerInfoSize);
end;
end;
end; function GetBuildInfoAsString: string;
var
V1, V2, V3, V4: word;
begin
GetBuildInfo(V1, V2, V3, V4);
Result := IntToStr(V1) + '.' + IntToStr(V2) + '.' +
IntToStr(V3) + '.' + IntToStr(V4);
end;
{$ENDIF} procedure TForm1.FormCreate(Sender: TObject);
{$IFDEF MSWINDOWS}
begin
Memo1.BeginUpdate; Memo1.Lines.Add('OS : Windows');
Memo1.Lines.Add('ver : ' + GetBuildInfoAsString); Memo1.EndUpdate;
end;
{$ENDIF} {$IFDEF ANDROID}
var PackageInfo: JPackageInfo;
PackageName: JString;
begin
Memo1.BeginUpdate; Memo1.Lines.Add('OS : Android');
Memo1.Lines.Add('applicationLabel : ' + GetApplicationTitle); PackageName := SharedActivityContext.getPackageName;
Memo1.Lines.Add('packageName : ' + JStringToString(PackageName)); PackageInfo := SharedActivityContext.getPackageManager.getPackageInfo(PackageName, 0);
Memo1.Lines.Add('versionName : ' + JStringToString(PackageInfo.versionName)); Memo1.EndUpdate;
end;
{$ENDIF} {$IF Defined(IOS) or Defined(MACOS)}
var AppNameKey: Pointer;
AppBundle: NSBundle;
NSAppName: NSString;
begin
Memo1.BeginUpdate; Memo1.Lines.Add('OS : iOS');
AppBundle := TNSBundle.Wrap(TNSBundle.OCClass.mainBundle); AppNameKey := (NSSTR('CFBundleName') as ILocalObject).GetObjectID;
NSAppName := TNSString.Wrap(AppBundle.infoDictionary.objectForKey(AppNameKey));
Memo1.Lines.Add('CFBundleName : ' + UTF8ToString(NSAppName.UTF8String)); AppNameKey := (NSSTR('CFBundleDisplayName') as ILocalObject).GetObjectID;
NSAppName := TNSString.Wrap(AppBundle.infoDictionary.objectForKey(AppNameKey));
Memo1.Lines.Add('CFBundleDisplayName : ' + UTF8ToString(NSAppName.UTF8String)); AppNameKey := (NSSTR('CFBundleIdentifier') as ILocalObject).GetObjectID;
NSAppName := TNSString.Wrap(AppBundle.infoDictionary.objectForKey(AppNameKey));
Memo1.Lines.Add('CFBundleIdentifier : ' + UTF8ToString(NSAppName.UTF8String)); AppNameKey := (NSSTR('CFBundleVersion') as ILocalObject).GetObjectID;
NSAppName := TNSString.Wrap(AppBundle.infoDictionary.objectForKey(AppNameKey));
Memo1.Lines.Add('CFBundleVersion : ' + UTF8ToString(NSAppName.UTF8String)); Memo1.EndUpdate;
end;
{$ENDIF} end.
05-11 20:14