Mega Code Archive

 
Categories / Delphi / VCL
 

How to show your application version in a label

Title: How to show your application version in a label. Question: How i can show the version number of my application in a form? Answer: First of all, sorry for my bad english, but i don't speak it usually. There are two methods to show your application version number. One of them is to write it manually in a label. But is a few laborious, because you must rewrite it everytime you release a new version or rebuild your project. The other one is to write a function than make it for you. To do this, you can use the following functions. Just put there in your code. // -------------------------------------------------------------------------// procedure GetBuildInfo(var V1, V2, V3, V4: Word); var VerInfoSize, VerValueSize, Dummy : DWORD; VerInfo : Pointer; VerValue : PVSFixedFileInfo; begin VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy); GetMem(VerInfo, VerInfoSize); GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo); VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize); With VerValue^ do begin V1 := dwFileVersionMS shr 16; V2 := dwFileVersionMS and $FFFF; V3 := dwFileVersionLS shr 16; V4 := dwFileVersionLS and $FFFF; end; FreeMem(VerInfo, VerInfoSize); end; // -------------------------------------------------------------------------// function kfVersionInfo: String; var V1, // Major Version V2, // Minor Version V3, // Release V4: Word; // Build Number begin GetBuildInfo(V1, V2, V3, V4); Result := IntToStr(V1) + '.' + IntToStr(V2) + '.' + IntToStr(V3) + '.' + IntToStr(V4); end; // -------------------------------------------------------------------------// Finally, put a TLabel on your MainForm and write this: Label1.Caption := 'My Application - Version ' + kfVersionInfo; That's All!! You can also show the version number in the MainForm Caption: MainForm.Caption := 'My Application - Version ' + kfVersionInfo; I Hope this be usefull for someone.