The FMX code below was copied and pasted from a source long ago.

The FMX code below was copied and pasted from a source long ago.

Compiled with earlier versions of Delphi, it is working fine in the field.

However, if compiled and run with Delphi 10.2, Update 2, CFStr after the first line is nil, causing a crash on the CFStringGetLength call.

How can one reliably read the current version of an app on OSX (Sierra, 10.12.4)


function GetVersionFromExe: String;
var
CFStr: CFStringRef;
Range: CFRange;
begin
CFStr := CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle, kCFBundleVersionKey);
Range.location := 0;
Range.length := CFStringGetLength(CFStr);
SetLength(Result, Range.length);
CFStringGetCharacters(CFStr, Range, PChar(Result));
end;

Comments

  1. Chris Rolliston You gave on Delphi's OS X support? That's worrying, considering you literally wrote the book on it!

    ReplyDelete
  2. Joseph Mitzen Chris' profile picture depicts that very moment ;-)

    ReplyDelete
  3. Chris Rolliston Thanks, Chris. You were right. Somehow my project had lost all of the plist Key-Value items from the grid on the Project, Options, Version Info screen. :-( I rolled back to .dproj file that was intact.

    Thanks to others for their code samples and suggestions.

    ReplyDelete

Post a Comment