Pages

Tuesday, December 20, 2011

How to display version info in delphi

As we know, in delphi we can set application version via IDE. To do that go to Project->Options->Version Info. Check 'Include version information in project'. The next question is how to display our version info in form??, For example in caption form.
Below is the steps to do that :
  1. Create function to get version info:
    function  GetAppVersion:string;
       var
        Size, Size2: DWord;
        Pt, Pt2: Pointer;
       begin
         Size := GetFileVersionInfoSize(PChar (ParamStr (0)), Size2);
         if Size > 0 then
         begin
           GetMem (Pt, Size);
           try
              GetFileVersionInfo (PChar (ParamStr (0)), 0, Size, Pt);
              VerQueryValue (Pt, '\', Pt2, Size2);
              with TVSFixedFileInfo (Pt2^) do
              begin
                Result:= ' Ver '+
                         IntToStr (HiWord (dwFileVersionMS)) + '.' +
                         IntToStr (LoWord (dwFileVersionMS)) + '.' +
                         IntToStr (HiWord (dwFileVersionLS)) + '.' +
                         IntToStr (LoWord (dwFileVersionLS));
             end;
           finally
             FreeMem (Pt);
           end;
         end;
       end;
    
  2. To make it display in form caption, write this script OnCreate events form
    Form1.Caption:=Form1.Caption+GetAppVersion;
    
Your application will look like this :

get version on form caption

No comments:

Post a Comment

Don't Forget To Join Our Community
×
Widget