How to determine Delphi Application Version

后端 未结 6 902
悲哀的现实
悲哀的现实 2020-12-08 04:31

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

6条回答
  •  遥遥无期
    2020-12-08 05:20

    Here is how I do it. I put this in almost all of my small utilities:

    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;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Form1.Caption := Form1.Caption + ' - v' + GetBuildInfoAsString;
    end;
    

提交回复
热议问题