John Fistere
asked on
In Delph 2007, I would like to increment a version counter each time I build my application.
I am running Delphi 2007 for Win32 under Win XP SR-2 and have successfully converted my D5 application, except for VersInfo. I use it to increment part of the version number for each build. I don't really use the complete VersInfo system. I can't get it to work under D2007, and the program writer has not responded to my email.
All I really need is an integer that increments each time I build my application, and not when I compile it.
Does D2007 have that kind of feature, or can someone tell me how to produce the same function?
Thanks,
John Fistere
All I really need is an integer that increments each time I build my application, and not when I compile it.
Does D2007 have that kind of feature, or can someone tell me how to produce the same function?
Thanks,
John Fistere
It is the same in D7
ASKER
Thanks. I still need some more help. What I've done so far is:
var
FileVer: string;
Ch: Char;
Dummy: dword;
Handle: cardinal;
VersionSize: integer;
begin
:
:
VersionSize := GetFileVersionInfoSize('Mu ltiGraph.e xe',Handle );
ShowMessage('VersionSize = '+IntToStr(VersionSize));
GetFileVersionInfo('MultiG raph.exe', Dummy,Vers ionSize,^F ileVer);
I get at an error at ^FileVer. I am really not experienced with pointers.
The error is E2010 Incompatible types: 'Ponter' and 'Char'
I want to display the version in my application.
Thanks,
John Fistere
var
FileVer: string;
Ch: Char;
Dummy: dword;
Handle: cardinal;
VersionSize: integer;
begin
:
:
VersionSize := GetFileVersionInfoSize('Mu
ShowMessage('VersionSize = '+IntToStr(VersionSize));
GetFileVersionInfo('MultiG
I get at an error at ^FileVer. I am really not experienced with pointers.
The error is E2010 Incompatible types: 'Ponter' and 'Char'
I want to display the version in my application.
Thanks,
John Fistere
I use this unit to decode version info of program. The initialization section shows how to call the function. This unit, included in your app, gives you all useful data (for me) from the exe file in InformacionDelSistema (translated as ApplicationInfo) structure.
unit uInformacionDelSistema;
interface
type TInformacionDelSistema = record
Nombre,
Version,
Cliente,
Comentarios: string;
end;
var InformacionDelSistema: TInformacionDelSistema;
implementation
uses Windows, SysUtils, Forms;
function DecodeVersionInfo(pInfo : pointer): TInformacionDelSistema;
var
pItem : pointer;
itemLen : UInt;
FixedFileInfo : PVSFixedFileInfo;
VersionSection: string;
TempStr : string;
Resultado: TInformacionDelSistema;
begin
Resultado.Nombre := 'SISTEMA';
Resultado.Version := '1.0.0.0';
Resultado.Cliente := '';
Resultado.Comentarios := '';
if VerQueryValue(pInfo, '\', Pointer(FixedFileInfo), itemLen) then
begin
{File Version}
TempStr := IntToStr(HIWORD(FixedFileI nfo^.dwFil eVersionMS )) + '.' +
IntToStr(LOWORD(FixedFileI nfo^.dwFil eVersionMS )) + '.' +
IntToStr(HIWORD(FixedFileI nfo^.dwFil eVersionLS )) + '.' +
IntToStr(LOWORD(FixedFileI nfo^.dwFil eVersionLS ));
{ This will make it compatible with all other Version programs }
{ And fit into Microsoft's standard's }
while ((Copy(TempStr, Length(TempStr), 1)='0') or
(Copy(TempStr, Length(TempStr), 1)='.')) do
TempStr := copy(TempStr, 1, length(TempStr)-1);
if (Pos('.', TempStr)<=0) then
TempStr := TempStr + '.0';
{Product Version}
TempStr := IntToStr(HIWORD(FixedFileI nfo^.dwPro ductVersio nMS)) + '.' +
IntToStr(LOWORD(FixedFileI nfo^.dwPro ductVersio nMS)) + '.' +
IntToStr(HIWORD(FixedFileI nfo^.dwPro ductVersio nLS)) + '.' +
IntToStr(LOWORD(FixedFileI nfo^.dwPro ductVersio nLS));
Resultado.Version := TempStr;
{CopyRight Strings}
VersionSection := '\StringFileInfo\' + IntToHex($409, 4) + IntToHex(1252, 4) + '\';
if VerQueryValue(pInfo, PChar(VersionSection + 'ProductName'), pItem, itemLen) then
Resultado.Nombre := PChar(pItem);
if VerQueryValue(pInfo, PChar(VersionSection + 'CompanyName'), pItem, itemLen) then
Resultado.Cliente := PChar(pItem);
if VerQueryValue(pInfo, PChar(VersionSection + 'Comments'), pItem, itemLen) then
Resultado.Comentarios := PChar(pItem);
end;
Result := Resultado;
end;
procedure GetVersionInfo(FFileName: string);
var versionHandle, versionSize : DWord;
pVersionInfo : pointer;
begin
versionSize := GetFileVersionInfoSize(PCh ar(FFileNa me), versionHandle);
if versionSize = 0 then
exit;
getMem(pVersionInfo, versionSize);
try
if GetFileVersionInfo(PChar(F FileName), versionHandle, versionSize, pVersionInfo) then
InformacionDelSistema := DecodeVersionInfo(pVersion Info);
finally
freeMem(pVersionInfo, versionSize);
end;
end;
initialization
GetVersionInfo(Lowercase(E xpandFilen ame(Applic ation.Exen ame)));
end.
Hope this help!!
unit uInformacionDelSistema;
interface
type TInformacionDelSistema = record
Nombre,
Version,
Cliente,
Comentarios: string;
end;
var InformacionDelSistema: TInformacionDelSistema;
implementation
uses Windows, SysUtils, Forms;
function DecodeVersionInfo(pInfo : pointer): TInformacionDelSistema;
var
pItem : pointer;
itemLen : UInt;
FixedFileInfo : PVSFixedFileInfo;
VersionSection: string;
TempStr : string;
Resultado: TInformacionDelSistema;
begin
Resultado.Nombre := 'SISTEMA';
Resultado.Version := '1.0.0.0';
Resultado.Cliente := '';
Resultado.Comentarios := '';
if VerQueryValue(pInfo, '\', Pointer(FixedFileInfo), itemLen) then
begin
{File Version}
TempStr := IntToStr(HIWORD(FixedFileI
IntToStr(LOWORD(FixedFileI
IntToStr(HIWORD(FixedFileI
IntToStr(LOWORD(FixedFileI
{ This will make it compatible with all other Version programs }
{ And fit into Microsoft's standard's }
while ((Copy(TempStr, Length(TempStr), 1)='0') or
(Copy(TempStr, Length(TempStr), 1)='.')) do
TempStr := copy(TempStr, 1, length(TempStr)-1);
if (Pos('.', TempStr)<=0) then
TempStr := TempStr + '.0';
{Product Version}
TempStr := IntToStr(HIWORD(FixedFileI
IntToStr(LOWORD(FixedFileI
IntToStr(HIWORD(FixedFileI
IntToStr(LOWORD(FixedFileI
Resultado.Version := TempStr;
{CopyRight Strings}
VersionSection := '\StringFileInfo\' + IntToHex($409, 4) + IntToHex(1252, 4) + '\';
if VerQueryValue(pInfo, PChar(VersionSection + 'ProductName'), pItem, itemLen) then
Resultado.Nombre := PChar(pItem);
if VerQueryValue(pInfo, PChar(VersionSection + 'CompanyName'), pItem, itemLen) then
Resultado.Cliente := PChar(pItem);
if VerQueryValue(pInfo, PChar(VersionSection + 'Comments'), pItem, itemLen) then
Resultado.Comentarios := PChar(pItem);
end;
Result := Resultado;
end;
procedure GetVersionInfo(FFileName: string);
var versionHandle, versionSize : DWord;
pVersionInfo : pointer;
begin
versionSize := GetFileVersionInfoSize(PCh
if versionSize = 0 then
exit;
getMem(pVersionInfo, versionSize);
try
if GetFileVersionInfo(PChar(F
InformacionDelSistema := DecodeVersionInfo(pVersion
finally
freeMem(pVersionInfo, versionSize);
end;
end;
initialization
GetVersionInfo(Lowercase(E
end.
Hope this help!!
ASKER
I got some more info, and here is how I have modified the code:
var
FileVer: PAnsiChar;
InfoHandle: cardinal;
VersionInfoSize: dword;
ptrVersionInfo: pointer;
ptrInfo: pointer;
begin
:
:
VersionInfoSize := GetFileVersionInfoSize('Mu ltiGraph.e xe',InfoHa ndle);
GetMem(ptrVersionInfo,Vers ionInfoSiz e);
ShowMessage('VersionInfoSi ze = '+IntToStr(VersionInfoSize ));
GetFileVersionInfo('MultiG raph.exe', InfoHandle ,VersionIn foSize,ptr VersionInf o);
VerQueryValue(ptrVersionIn fo,FileVer ,ptrInfo,V ersionInfo Size);
ShowMessage('FileVer = '+FileVer);
It compiles and runs but I get garbage for FileVer in the last statement. The basic problem is that I don't understand the basics of what is going on.
John Fistere
var
FileVer: PAnsiChar;
InfoHandle: cardinal;
VersionInfoSize: dword;
ptrVersionInfo: pointer;
ptrInfo: pointer;
begin
:
:
VersionInfoSize := GetFileVersionInfoSize('Mu
GetMem(ptrVersionInfo,Vers
ShowMessage('VersionInfoSi
GetFileVersionInfo('MultiG
VerQueryValue(ptrVersionIn
ShowMessage('FileVer = '+FileVer);
It compiles and runs but I get garbage for FileVer in the last statement. The basic problem is that I don't understand the basics of what is going on.
John Fistere
replace ShowMessage line with
FileVerStr := IntToStr(HIWORD(PVSFixedFi leInfo(ptr Info)^.dwP roductVers ionMS)) + '.' +
IntToStr(LOWORD(PVSFixedFi leInfo(ptr Info)^.dwP roductVers ionMS)) + '.' +
IntToStr(HIWORD(PVSFixedFi leInfo(ptr Info)^.dwP roductVers ionLS)) + '.' +
IntToStr(LOWORD(PVSFixedFi leInfo(ptr Info)^.dwP roductVers ionLS));
ShowMessage(´FileVer = ´ + FileVerStr);
FileVerStr is just string type.
FileVerStr := IntToStr(HIWORD(PVSFixedFi
IntToStr(LOWORD(PVSFixedFi
IntToStr(HIWORD(PVSFixedFi
IntToStr(LOWORD(PVSFixedFi
ShowMessage(´FileVer = ´ + FileVerStr);
FileVerStr is just string type.
ASKER
spk,
When I make your suggested modification I get the result:
FileVerStr = 191.2080.191.5926.
In the IDE, I followed earlier instructions: Project / Options / Version Info, and set FileVersion to 6.0.0.7. It is this string I expected to see.
Thanks, but something is not connecting.
John
When I make your suggested modification I get the result:
FileVerStr = 191.2080.191.5926.
In the IDE, I followed earlier instructions: Project / Options / Version Info, and set FileVersion to 6.0.0.7. It is this string I expected to see.
Thanks, but something is not connecting.
John
ASKER
Also, I rebuilt MultiGraph and the Build Number stayed at 5926.
John
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well, I finally realized that I was going to have to add a unit. Since spk2000ar proposed the first unit, I tried it first. I thought it would be good to add a little international flavor to my application. However, i couldn't make it work, and it seemed that the reason might be stuff missing from the interface section. Or that I did not know how to use what was there.
So I tried MerijnB's unit and it worked just fine. All I wanted was the Major version and the Build, and I was able to get those directly.
Thanks to all who helped!
John
So I tried MerijnB's unit and it worked just fine. All I wanted was the Major version and the Build, and I was able to get those directly.
Thanks to all who helped!
John
But in BDS2006 it's at: project -> options -> version info (check both 'include version number in project' and 'auto-increment build number')
you might find it in the same place for D2007