GetCurrentVersion

From Lazarus wiki
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;

 ...