Version information

Is the version information accessible from within a program, like major, minor and revisions of a program? If so, how? Thanks
ponedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
yep
here is unit from "tomes of delphi" book that shows how:

unit GetVerInfoU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, FileCtrl, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    TabControl1: TTabControl;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    FilterComboBox1: TFilterComboBox;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Bevel1: TBevel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    procedure FileListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FileListBox1Click(Sender: TObject);
var
  VerInfoSize: DWORD;         // holds the size of the version info resource
  GetInfoSizeJunk: DWORD;     // a junk variable, its value is ignored
  VersionInfo: Pointer;       // points to the version info resource
  Translation: Pointer;       // holds version info translation table
  InfoPointer: Pointer;       // a pointer to version information
  VersionInfoSize: UINT;      // holds the size of version information
  VersionValue: string;       // holds the version info request string
begin
  {retrieve the size of the version information resource, if one exists}
  VerInfoSize := 0;
  VerInfoSize := GetFileVersionInfoSize(PChar(FileListBox1.FileName),
                                        GetInfoSizeJunk);

  {if there was a version information resource available...}
  if VerInfoSize>0 then
  begin
    {hide the 'not available' indicator}
    Label1.Visible := FALSE;

    {retrieve enough memory to hold the version resource}
    GetMem(VersionInfo, VerInfoSize);

    {retrieve the version resource for the selected file}
    GetFileVersionInfo(PChar(FileListBox1.FileName), 0, VerInfoSize, VersionInfo);

    {retrieve a pointer to the translation table}
    VerQueryValue(VersionInfo, '\\VarFileInfo\\Translation', Translation, VersionInfoSize);

    {initialize the version value request string}
    VersionValue :='\\StringFileInfo\\'+
                  IntToHex(LoWord(LongInt(Translation^)),4)+
                  IntToHex(HiWord(LongInt(Translation^)),4)+
                  '\\';

    {retrieve and display the company name}
    VerQueryValue(VersionInfo, PChar(VersionValue+'CompanyName'), InfoPointer,
                  VersionInfoSize);
    Label17.Caption := string(PChar(InfoPointer));

    {retrieve and display the file description}
    VerQueryValue(VersionInfo, PChar(VersionValue+'FileDescription'), InfoPointer,
                  VersionInfoSize);
    Label16.Caption := string(PChar(InfoPointer));

    {retrieve and display the file version}
    VerQueryValue(VersionInfo, PChar(VersionValue+'FileVersion'), InfoPointer,
                  VersionInfoSize);
    Label15.Caption := string(PChar(InfoPointer));

    {retrieve and display the internal file name}
    VerQueryValue(VersionInfo, PChar(VersionValue+'InternalName'), InfoPointer,
                  VersionInfoSize);
    Label14.Caption := string(PChar(InfoPointer));

    {retrieve and display the legal copyright}
    VerQueryValue(VersionInfo, PChar(VersionValue+'LegalCopyright'), InfoPointer,
                  VersionInfoSize);
    Label13.Caption := string(PChar(InfoPointer));

    {retrieve and display the legal trademarks}
    if VerQueryValue(VersionInfo, PChar(VersionValue+'LegalTrademarks'), InfoPointer,
                     VersionInfoSize) then
      Label19.Caption := string(PChar(InfoPointer))
    else
      Label19.Caption := '';

    {retrieve and display the original file name}
    VerQueryValue(VersionInfo, PChar(VersionValue+'OriginalFilename'), InfoPointer,
                  VersionInfoSize);
    Label12.Caption := string(PChar(InfoPointer));

    {retrieve and display the product name}
    VerQueryValue(VersionInfo, PChar(VersionValue+'ProductName'), InfoPointer,
                  VersionInfoSize);
    Label11.Caption := string(PChar(InfoPointer));

    {retrieve and display the product version}
    VerQueryValue(VersionInfo, PChar(VersionValue+'ProductVersion'), InfoPointer,
                  VersionInfoSize);
    Label10.Caption := string(PChar(InfoPointer));

    {retrieve and display the comments. some version info resources may
     not have this information.}
    if VerQueryValue(VersionInfo, PChar(VersionValue+'Comments'), InfoPointer,
                     VersionInfoSize) then
      Label21.Caption := string(PChar(InfoPointer))
    else
      Label21.Caption := '';

    {retrieve and display file build flags}
    if VerQueryValue(VersionInfo, '\', InfoPointer, VersionInfoSize) then
    begin
      CheckBox1.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_DEBUG);
      CheckBox2.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_PRERELEASE);
      CheckBox3.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_PATCHED);
      CheckBox4.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_PRIVATEBUILD);
      CheckBox5.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_INFOINFERRED);
      CheckBox6.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_SPECIALBUILD);
    end
    else
    begin
      CheckBox1.Checked := FALSE;
      CheckBox2.Checked := FALSE;
      CheckBox3.Checked := FALSE;
      CheckBox4.Checked := FALSE;
      CheckBox5.Checked := FALSE;
      CheckBox6.Checked := FALSE;
    end;

    {free the version resource memory}
    FreeMem(VersionInfo, VerInfoSize);
  end
  else
  begin
    {otherwise, indicate that no version information is available}
    Label1.Visible := TRUE;

    {delete any previous version information}
    Label17.Caption := '';
    Label16.Caption := '';
    Label15.Caption := '';
    Label14.Caption := '';
    Label13.Caption := '';
    Label12.Caption := '';
    Label11.Caption := '';
    Label10.Caption := '';
    Label19.Caption := '';
    Label21.Caption := '';

    CheckBox1.Checked := FALSE;
    CheckBox2.Checked := FALSE;
    CheckBox3.Checked := FALSE;
    CheckBox4.Checked := FALSE;
    CheckBox5.Checked := FALSE;
    CheckBox6.Checked := FALSE;
  end;
end;

end.


Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.