Application version

Using this simple function, you will be able to read version information from any application executable. It’s very useful for example to show your own application version on title bar or “About” dialog.
First of all, make sure you check “Include version information in project” in Project Options dialog. The version information will be included to your executable and can be viewed from Explorer using context menu. But using function below, you can read version info from your app.

function AppVersion(const Filename: string):string;
var dwHandle: THandle;
    dwSize: DWORD;
    lpData, lpData2: Pointer;
    uiSize: UINT;
begin
  Result := '';
  dwSize := GetFileVersionInfoSize(PChar(FileName), dwSize);
  if dwSize <> 0 then
  begin
    GetMem(lpData, dwSize);
    if GetFileVersionInfo(PChar(FileName), dwHandle, dwSize, lpData) then
      begin
        uiSize := Sizeof(TVSFixedFileInfo);
        VerQueryValue(lpData, '', lpData2, uiSize);
        with PVSFixedFileInfo(lpData2)^ do
          Result := Format('%d.%02d.%02d.%02d', [HiWord(dwProductVersionMS), LoWord(dwProductVersionMS),HiWord(dwProductVersionLS), LoWord(dwProductVersionLS)]);
      end;
    FreeMem(lpData, dwSize);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('Version: ' + AppVersion(Application.ExeName));
end;