unit uDemo;

interface

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

type
  TfrmDemo = class(TForm)
    PageControl: TPageControl;
    Panel1: TPanel;
    btnClose: TButton;
    btnOpenFile: TButton;
    btnCloseTabs: TButton;
    ApFileVersionInformationReader: TApFileVersionInformationReader;
    procedure btnCloseClick(Sender: TObject);
    procedure btnOpenFileClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure PageControlMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
      Y: Integer);
    procedure btnCloseTabsClick(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure AddInformationPage(const Info: TApFileVersionInformation);
  public
    { Public-Deklarationen }
  end;

var
  frmDemo: TfrmDemo;

implementation

{$R *.dfm}

{--------------------------------------------------------------------------------------------------
  Display information in a new tab sheet.
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.AddInformationPage(const Info: TApFileVersionInformation);
var
  Sheet : TTabSheet;
  Memo : TMemo;
  i : Integer;
begin
  // Add new page and show infos in memo
  Sheet := TTabSheet.Create(PageControl);
  Sheet.PageControl := PageControl;
  Sheet.Caption := Info.Filename;
  PageControl.ActivePage := Sheet;

  Memo := TMemo.Create(Sheet);
  Memo.Parent := Sheet;
  Memo.Align := alClient;
  Memo.ScrollBars := ssBoth;

  Memo.Lines.Add('FileType: ' + Info.FileType);
  Memo.Lines.Add('CompanyName: ' + Info.CompanyName);
  Memo.Lines.Add('FileDescription: ' + Info.FileDescription);
  Memo.Lines.Add('FileVersion: ' + Info.FileVersion);
  Memo.Lines.Add('InternalName: ' + Info.InternalName);
  Memo.Lines.Add('LegalCopyRight: ' + Info.LegalCopyRight);
  Memo.Lines.Add('LegalTradeMarks: ' + Info.LegalTradeMarks);
  Memo.Lines.Add('OriginalFileName: ' + Info.OriginalFileName);
  Memo.Lines.Add('ProductName: ' + Info.ProductName);
  Memo.Lines.Add('ProductVersion: ' + Info.ProductVersion);
  Memo.Lines.Add('Comments: ' + Info.Comments);
  Memo.Lines.Add('SpecialBuildStr: ' + Info.SpecialBuildStr);
  Memo.Lines.Add('PrivateBuildStr: ' + Info.PrivateBuildStr);
  Memo.Lines.Add('FileFunction: ' + Info.FileFunction);

  Memo.Lines.Add('DebugBuild: ' + BoolToStr(Info.DebugBuild, True));
  Memo.Lines.Add('PreRelease: ' + BoolToStr(Info.PreRelease, True));
  Memo.Lines.Add('SpecialBuild: ' + BoolToStr(Info.SpecialBuild, True));
  Memo.Lines.Add('PrivateBuild: ' + BoolToStr(Info.PrivateBuild, True));
  Memo.Lines.Add('Patched: ' + BoolToStr(Info.Patched, True));
  Memo.Lines.Add('InfoInferred: ' + BoolToStr(Info.InfoInferred, True));

  for i := 0 to Length(Info.AdditionalProperties) - 1 do
    Memo.Lines.Add(Info.AdditionalProperties[i][0] + ': ' + Info.AdditionalProperties[i][1]);
end;

{--------------------------------------------------------------------------------------------------
  Close Application
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.btnCloseClick(Sender: TObject);
begin
  Close();
end;

{--------------------------------------------------------------------------------------------------
  Open file via OpenDialog
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.btnOpenFileClick(Sender: TObject);
var
  OpenDialog : TOpenDialog;
  Info : TApFileVersionInformation;
begin
  OpenDialog := TSaveDialog.Create(nil);
  OpenDialog.Options := [ofReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing, ofDontAddToRecent, ofForceShowHidden];
  try
    if (OpenDialog.Execute()) then
    begin
      // Read and how informations
      Info := TApFileVersionInformationReader.Read(OpenDialog.FileName);
      AddInformationPage(Info);
    end;
  finally
    FreeAndNil(OpenDialog);
  end;
end;

{--------------------------------------------------------------------------------------------------
  Read and show information of application on startup.
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.FormCreate(Sender: TObject);
begin
  AddInformationPage( ApFileVersionInformationReader.ApplicationVersionInformation );
end;

{--------------------------------------------------------------------------------------------------
  Close active tab sheet by clicking via middle mouse button on the tab itself.
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.PageControlMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
begin
  if (Button = mbMiddle) then
    PageControl.ActivePage.Free();
end;

{--------------------------------------------------------------------------------------------------
  Closes all information tabs.
 --------------------------------------------------------------------------------------------------}
procedure TfrmDemo.btnCloseTabsClick(Sender: TObject);
var
  i : Integer;
begin
  for i := PageControl.PageCount - 1 downto 0 do
    PageControl.Pages[i].Free();
end;


end.

