Article

From:
To:
Ken White
Subject:
Re: Version Control and Update 5 or XE3
Newsgroup:
embarcadero.public.delphi.install
URL:
Shortcut to this article

Re: Version Control and Update 5 or XE3

Ken,

Thanks to you, I got it to work.
Just in case anyone else wants to implement this solution, Below you will find the necessary steps
and auxiliary program.

Jim Fleming


A) Create your Version Info resource file in your project directory or wherever, with the following
contents, and file extension .rc:

{code}
#define CONST_VERSION "4.1.1.1003\000" // Note the \000 !!!! Here and elsewhere below !!!! C
string terminator !!!

1 VERSIONINFO FILEVERSION 1,0,0,1 PRODUCTVERSION 1,0,0,1 FILEOS 0x4 FILETYPE 0x1 { BLOCK "StringFileInfo" {
BLOCK "040904E4" // Will need changing if your language is not English and char-set not
1252 (multilingual).
{
VALUE "CompanyName", "Whatever\000"
VALUE "FileDescription", "Whatever\000"
VALUE "FileVersion", CONST_VERSION
VALUE "InternalName", "My Internal Name\000"
VALUE "LegalCopyright", "Copyright © whoever\000"
VALUE "LegalTrademarks", "\000"
VALUE "OriginalFileName", "If you wish\000"
VALUE "ProductName", "What pleases you\000"
VALUE "ProductVersion", CONST_VERSION
VALUE "Comments", "Anything you wish to add\000"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0409 0x04E4
}
}
{code}

B) Create a new project in some folder, code of only module should be similar to:

{code}
unit FormIncrementBuildNumber;

interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
  Vcl.Controls,   Vcl.Forms,        Vcl.Dialogs,
  Vcl.StdCtrls,   System.IOUtils,   System.StrUtils;

type   TIncrementBuildNumber = class(TForm)     IncrementingBuildNumberLabel: TLabel;
    procedure FormShow (Sender: TObject);     procedure FormActivate(Sender: TObject);   private     { Private declarations }   public     { Public declarations }   end;
var   IncrementBuildNumber: TIncrementBuildNumber;
implementation
{$R *.dfm}
procedure TIncrementBuildNumber.FormShow (Sender: TObject); var   Resource_File_Contents: TStringList;   Full_File_Name_And_Path: string;   First_Line_Of_File: string;   Position_First_Dot: Integer;   Position_Second_Dot: Integer;   Position_Third_Dot: Integer;   Position_Trailing_Backslash: Integer;   Start_of_Build_Number: Integer;   Length_of_Build_Number: Integer;   Build_Number_In_ASCII: string;   Build_Number_Numeric: Integer;   Old_Resource_File_Name: string;
  Success: Boolean; begin   if (System.ParamCount <> 1) then     begin       ShowMessage ('Resource File name not in first command-line parameter.');       Exit;     end;
  Full_File_Name_And_Path := System.ParamStr(1);   if (not TFile.Exists(Full_File_Name_And_Path, False)) then     begin       ShowMessage ('Resource file ' + Full_File_Name_And_Path + ' not found.');       Exit;     end;
  Resource_File_Contents := TStringList.Create;   try     Resource_File_Contents.LoadFromFile(Full_File_Name_And_Path);     First_Line_Of_File := Resource_File_Contents.Strings[0];
    if (Copy(First_Line_Of_File, 1, 21) <> '#define CONST_VERSION') then       begin
ShowMessage ('First line of Version Info must start with "#define CONST_VERSION".' + #13 +
                     'Version not incremented.');
        Exit;
      end;

    Position_First_Dot := Pos('.', First_Line_Of_File);     if (Position_First_Dot = 0) then       begin
ShowMessage ('Version must have format "a.b.c.d".' + #13 + 'Build Number not incremented.');
        Exit;
      end;

    Position_Second_Dot := PosEx('.', First_Line_Of_File, Position_First_Dot+1);     if (Position_Second_Dot = 0) then       begin
ShowMessage ('Version must have format "a.b.c.d".' + #13 + 'Build Number not incremented.');
        Exit;
      end;

Position_Third_Dot := PosEx('.', First_Line_Of_File, Position_Second_Dot+1);
    if (Position_Third_Dot = 0) then
      begin
ShowMessage ('Version must have format "a.b.c.d".' + #13 + 'Build Number not incremented.');
        Exit;
      end;

Position_Trailing_Backslash := PosEx('\', First_Line_Of_File, Position_Third_Dot+1);
    if (Position_Trailing_Backslash = 0) then
      begin
ShowMessage ('Version must have format "a.b.c.d\000".' + #13 + 'Build Number not
incremented.');
        Exit;
      end;

    Start_of_Build_Number := Position_Third_Dot + 1;
Length_of_Build_Number := Position_Trailing_Backslash - Start_of_Build_Number;

    if (Length_of_Build_Number < 1) then
      begin
ShowMessage ('Build Number must be present.' + #13 + 'Build Number not incremented.');
        Exit;
      end;

    Build_Number_In_ASCII := Copy (First_Line_Of_File, Start_of_Build_Number, Length_of_Build_Number);     Success := TryStrToInt (Build_Number_In_ASCII, Build_Number_Numeric);     if (not Success) then       begin
ShowMessage ('Build Number must be numeric integer.' + #13 + 'Build Number not
incremented.');
        Exit;
      end;

    Build_Number_Numeric := Build_Number_Numeric + 1;
    Build_Number_In_ASCII := IntToStr(Build_Number_Numeric);
Resource_File_Contents.Strings[0] := Copy(First_Line_Of_File, 1, Position_Third_Dot) +
                                         Build_Number_In_ASCII +                                          '\000"';
    Old_Resource_File_Name := Full_File_Name_And_Path;
Old_Resource_File_Name := TPath.ChangeExtension (Old_Resource_File_Name, '~rc');
    if (TFile.Exists(Old_Resource_File_Name, False)) then
      begin
        TFile.Delete(Old_Resource_File_Name);
      end;

    Success := RenameFile(Full_File_Name_And_Path, Old_Resource_File_Name);     if (not Success) then       begin
ShowMessage ('Error renaming old resource file to have extension "~rc".' + #13 + 'Build
Number not incremented.');
        Exit;
      end;

    Resource_File_Contents.SaveToFile(Full_File_Name_And_Path);
  finally     Resource_File_Contents.Free;   end; end;
procedure TIncrementBuildNumber.FormActivate (Sender: TObject); begin   Close; end;
end. {code}
C) In Project Options of the project whose build number should be incremented:       - Remove the tick "include version info".
- Add a pre-build event with the following text, as written, including the two pairs of
double-quotes, substituting the parts within < >:
"<full file name and path of the auto-increment program exe>" "<full file name and path of
the .rc resource file>"

D) Add to the project source, right below the "program" keyword:
{code}
{$R '<whatever you called it>.res' '<whatever you called it>.rc'} // I think both names must
be the same here: IIRC, got errors when they were different.
{code}

E) Compile, run and enjoy the return of Auti-Increment build numbers, despite Embarcadero's having
removed the facility.

EOJ
FYI: Phrase searches are enclosed in either single or double quotes
 
 
 
24-Jul 11:00 utc Operating system upgrade in process, expect some down time.
Originally created by
[Tamarack]
Tue, 17 Sep 2019 09:18:04 UTC
Copyright © 2009-2019
HREF Tools Corp.