How to determine Delphi Application Version

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

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

6条回答
  •  自闭症患者
    2020-12-08 05:07

    Pass the full file name of your EXE to this function, and it will return a string like: 2.1.5.9, or whatever your version # is.

    function GetFileVersion(exeName : string): string;
    const
      c_StringInfo = 'StringFileInfo\040904E4\FileVersion';
    var
      n, Len : cardinal;
      Buf, Value : PChar;
    begin
      Result := '';
      n := GetFileVersionInfoSize(PChar(exeName),n);
      if n > 0 then begin
        Buf := AllocMem(n);
        try
          GetFileVersionInfo(PChar(exeName),0,n,Buf);
          if VerQueryValue(Buf,PChar(c_StringInfo),Pointer(Value),Len) then begin
            Result := Trim(Value);
          end;
        finally
          FreeMem(Buf,n);
        end;
      end;
    end;
    

    After defining that, you can use it to set your form's caption like so:

    procedure TForm1.FormShow(Sender: TObject);
    begin 
      //ParamStr(0) is the full path and file name of the current application
      Form1.Caption := Form1.Caption + ' version ' + GetFileVersion(ParamStr(0));
    end;
    

提交回复
热议问题