How to determine Delphi Application Version

Viewed 43679

Want to obtain Delphi Application build number and post into title bar

7 Answers

My code:

uses unit Winapi.Windows;

function GetModuleVersion(Instance: THandle; out iMajor, iMinor, iRelease, iBuild: Integer): Boolean;
var
    fileInformation: PVSFIXEDFILEINFO;
    verlen: Cardinal;
    rs: TResourceStream;
    m: TMemoryStream;
begin

   result := false;

    m := TMemoryStream.Create;
    try
        try
          rs := TResourceStream.CreateFromID(Instance, 1, RT_VERSION);
          try
              m.CopyFrom(rs, rs.Size);
          finally
              rs.Free;
          end;
        except
          exit;
        end;

        m.Position:=0;
        if not VerQueryValue(m.Memory, '\', Pointer(fileInformation), verlen) then
        begin
          iMajor := 0;
          iMinor := 0;
          iRelease := 0;
          iBuild := 0;
          Exit;
        end;

        iMajor := fileInformation.dwFileVersionMS shr 16;
        iMinor := fileInformation.dwFileVersionMS and $FFFF;
        iRelease := fileInformation.dwFileVersionLS shr 16;
        iBuild := fileInformation.dwFileVersionLS and $FFFF;
    finally
        m.Free;
    end;

    Result := True;
end;

Usage:

  if GetModuleVersion(HInstance, iMajor, iMinor, iRelease, iBuild) then
    ProgramVersion := inttostr(iMajor)+'.'+inttostr(iMinor)+'.'+inttostr(iRelease)+'.'+inttostr(iBuild);
Related