Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm on Delphi RAD Studio 10.2

How do you get the information from the settings in Project > Options > Version Info? I'm talking about the KEYS. Things like "LegalCopyright", "FileDescription", and "Comments" from that? These are stored in the dbproj file but I need to know how to get those key values in code so I can display them in some places in my application.

I know how to get the Title from Project > Options > Application > Appearance > Title. That's easy. It's just Application.Title. But the keys above are eluding me. I could write some code to get the values from the XML in the dproj file but it doesn't seem like we should have to do that.

Hope someone can help. Thanks,

Keith

By the way, does this tend to be a good place to ask Delphi questions? The Embarcadero forums are NOT any good from what I can see. I've been upgrading a Borland Delphi 7 project to RAD Studio 10.2. Back in the early 2000's the usenet groups were great for this sort of thing but those have gone the way of the dodo as we all know. I really need a solid place to get Delphi questions answered. :-)

What I have tried:

Very little. I can't find anything online that helps me figure this out. I've spent over an hour searching.
Posted
Updated 18-Dec-18 15:31pm
v2

1 solution

procedure TForm1.FormCreate(Sender: TObject);

   function ReadVerInfo(const fn: string;
                        var Desc: string;
                        const lv: integer = 0;
                        const ky: string = ''): string;
   var
     VerHandle,
     VerSize        : DWORD;
     pItem,
     pVerInfo       : Pointer;
     FixedFileInfo  : PVSFixedFileInfo;
     il             : UINT;
     version, key   : string;
     sRes,
     LangS, CharS	: string;
     pFName         : array [0..MAX_PATH-1] of Char;
   begin
     version:=''; Desc:=''; sRes:='';
     if fn<>'' then begin
       StrPCopy(pFName,fn);
       VerHandle:=0;
       VerSize:=GetFileVersionInfoSize(pFName,VerHandle);
       if VerSize=0 then Exit;
       GetMem(pVerInfo,VerSize);
       try
         if GetFileVersionInfo(pFName,VerHandle,VerSize,pVerInfo)
         then
         begin
           LangS:='0409'; CharS:='04E4';
           il:=0; pItem:=nil; FixedFileInfo:=nil;
           if VerQueryValue(pVerInfo,
                            '\VarFileInfo\Translation',pItem,il)
           then
           begin
             LangS:=IntToHex(  Integer(pItem^) and $0000FFFF     ,4);
             CharS:=IntToHex(((Integer(pItem^) and $FFFF0000) shr 16)
                                                        and $FFFF,4);
           end;
           if VerQueryValue(pVerInfo,'\',Pointer(FixedFileInfo),il)
           then
           with FixedFileInfo^
           do version:=
               IntToStr(HiWord(dwFileVersionMS))+'.'
              +IntToStr(LoWord(dwFileVersionMS))+'.'
              +IntToStr(HiWord(dwFileVersionLS))+'.'
              +IntToStr(LoWord(dwFileVersionLS));
           key:=ky;
           if key='' then key:='FileDescription';
           if VerQueryValue(pVerInfo,
              PChar('\StringFileInfo\'+LangS+CharS+'\'+Key),pItem,il)
           then
              Desc:=PChar(pItem);
           if VerQueryValue(pVerInfo,
              PChar('\StringFileInfo\'+LangS+CharS+'\FileVersion'),pItem,il)
           then
              version:=PChar(pItem);
         end;
       finally
         FreeMem(pVerInfo,VerSize);
         sRes:=version;
         if lv<>0 then
         begin
            sRes:='';
            if version[length(version)]<>'.' then version:=version+'.';
            for il:=1 to lv do
            begin
               if sRes<>'' then sRes:=sRes+'.';
               sRes:=sRes+copy(version,1,pos('.',version)-1);
               version:=copy(version,pos('.',version)+1,Length(version));
            end;
         end;
       end;
     end;
     ReadVerInfo:=sRes;
   end;
var
  sName, sVers: string;
begin
  sName:='';
  sVers:=ReadVerInfo(Application.ExeName, sName);
  Self.Caption:=sName+' (v'+sVers+')';
end
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900