GetCurrentVersion

From Lazarus wiki
Revision as of 12:18, 16 February 2020 by Trev (talk | contribs) (English translation of German page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
Windows logo - 2012.svg

This article applies to Windows only.

See also: Multiplatform Programming Guide

Deutsch (de) English (en)

Return to the Code Examples page.

This article deals with Windows programming.

The function determines the current version of your own program.

  uses
   Windows, SysUtils, ...;

   ...

 function funGetCurrentVersion: string;
 var
   lwdVerInfoSize: longword;
   lwdVerValueSize: longword;
   lwdDummy: longword;
   ptrVerInfo: pointer;
   VersionsInformation: PVSFixedFileInfo;

 begin

   lwdVerInfoSize: = GetFileVersionInfoSize(PChar(ParamStr(0)), lwdDummy);
   GetMem(ptrVerInfo, lwdVerInfoSize);
   GetFileVersionInfo(PChar(ParamStr(0)), 0, lwdVerInfoSize, ptrVerInfo);
   VerQueryValue (ptrVerInfo, '\', Pointer(VersionsInformation), lwdVerValueSize);

   with VersionsInformation^ do
   begin
     Result: = IntToStr (dwFileVersionMS shr 16);
     Result: = Result + '.'  + IntToStr(dwFileVersionMS and $ FFFF);
     Result: = Result + '.'  + IntToStr(dwFileVersionLS shr 16);
     Result: = Result + '.'  + IntToStr(dwFileVersionLS and $ FFFF);
   end;

   FreeMem(ptrVerInfo, lwdVerInfoSize);

 end;

 ...