!************************************** !
Name: access application version information programmatically. ! Description:This function will read the file version information from your application's executable file. It does this through the Win32 API functions GetFileVersionInfoSize(), GetFileVersionInfo(), and VerQueryValue(). This can be very useful if you have your IDE set to increment build numbers each time you compile your project, as it can be used to return the current version number. Since I use the version number in a lot of my applications, it's really a pain to have to update a global constant each time the version number changes. This makes it much easier. Please note: I found a version of this code in the Borland Delphi 6 help files, and modified it so it would be a function, and return only the file version information. Additionally, there were very few comments, so I commented much of the code as well. You can view the original code if you do a search in the help files for "Reading version information". ! By: filter ! ! ! Inputs:None ! ! Returns:A string containing the current file version of your application's executable file. ! !Assumes:None ! !Side Effects:None !This code is copyrighted and has limited warranties. !Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.542/lngWId.7/qx/vb/scripts/ShowCode.htm !for details.
!**************************************
function Application_Version: String; const InfoNum = 10; InfoStr: array[1..InfoNum] of string = ('CompanyName', 'FileDescription', 'FileVersion', 'InternalName', 'LegalCopyright', 'LegalTradeMarks', 'OriginalFileName', 'ProductName', 'ProductVersion', 'Comments'); var S: string; n, Len, i: DWORD; Buf: PChar; Value: PChar; begin S := Application.ExeName; //this application's EXE filename n := GetFileVersionInfoSize(PChar(S), n); // the return value is the size in bytes of the file's version information. Result := ''; (* this sets a default result in case a file version isn't found. I add this to functions because the compiler will bug you that the result may not be defined otherwise. you could change this, or remove it alltogether, although it's probably best to leave it. *) if n > 0 then begin Buf := AllocMem(n); // allocate the needed amount of memory into the buffer GetFileVersionInfo(PChar(S), 0, n, Buf); // store the file version information in the memory buffer. it stores all of the values listed in the InfoStr array. for i := 1 to InfoNum do if VerQueryValue(Buf, PChar('StringFileInfo\040904E4\' + InfoStr[i]), Pointer(Value), Len) then if trim(lowerCase(InfoStr[i])) = 'fileversion' then Result := Value;// loop through each value until we find the "FileVersion" information. FreeMem(Buf, n); // free the memory we stored in the buffer.
end;
end;
15 November 2007
Langganan:
Posting Komentar (Atom)
3 komentar:
Bravo, your idea is useful
Bravo, what excellent answer.
apa yang saya cari, terima kasih
Posting Komentar