Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You edited your question with a full compiling sample. Good!</p> <p>It is probably the easiest if you'd use the JCL for this (link is below). Then you could use TJclFileVersionInfo, which does all you want, and takes into account some esotheric things that the VersionInfo can hold.</p> <p>Then your business logic would become something like this:</p> <pre><code>function GetStringFileInfo( const Buffer: Pointer; const SubBlock: PChar; const LangCharSetString: string; const Kind: string): string; var QueryString: string; Data: Pointer; DataCharacters: PChar absolute Data; DataLen: LongWord; begin Result := ''; QueryString := Format('%s\StringFileInfo\%s\%s', [SubBlock, LangCharSetString, Kind]); if VerQueryValue(Buffer, PChar(QueryString), Data, DataLen) then Result := StrPas(DataCharacters); end; procedure GetVersionInfoStrings(var Comments: string; var ProductName: string; var Caption: string; var Version: string; var Copyright: string); type PLangCharSetInfo = ^TLangCharSetInfo; TLangCharSetInfo = record Lang: Word; CharSet: Word; end; var FileName: array [0 .. 260] of Char; SubBlock: array [0 .. 255] of Char; VerHandle: Cardinal; Size: Word; Buffer: Pointer; Data: Pointer; DataCharacters: PChar absolute Data; DataLen: LongWord; LangCharSetInfo: PLangCharSetInfo; LangCharSetString: string; begin Comments := 'No version information for this program is available!'; { Get size and allocate buffer for VerInfo } if GetModuleFileName(hInstance, FileName, SizeOf(FileName)) &gt; 0 then begin Size := GetFileVersionInfoSize(FileName, VerHandle); if Size &gt; 0 then begin GetMem(Buffer, Size); try if GetFileVersionInfo(FileName, VerHandle, Size, Buffer) then begin { Query first language and that language blocks version info } if VerQueryValue(Buffer, '\VarFileInfo\Translation', Pointer (LangCharSetInfo), DataLen) then begin LangCharSetString := IntToHex(LangCharSetInfo^.Lang, 4) + IntToHex(LangCharSetInfo^.CharSet, 4); ProductName := GetStringFileInfo(Buffer, SubBlock, LangCharSetString, 'ProductName'); Version := GetStringFileInfo(Buffer, SubBlock, LangCharSetString, 'FileVersion'); Copyright := GetStringFileInfo(Buffer, SubBlock, LangCharSetString, 'LegalCopyright'); Comments := GetStringFileInfo(Buffer, SubBlock, LangCharSetString, 'Comments'); Caption := ProductName; end; end; finally FreeMem(Buffer, Size); end; end end; end; </code></pre> <p>And in the UI, you will need to call your business logic, and put the results into the various controls.</p> <p>--jeroen</p> <p><strong>Answer before edit:</strong></p> <p>Your code does not compile as is, so without more context, it is hard to answer your quest.</p> <p>What are the data types of Buffer, SubBlock, LongCharSetString and DataLen? How did you obtain Buffer?</p> <p>Is Data really meant to be a Pointer to (Ansi or Unicode) characters? Shouldn't it ultimately be of pointing to PVSFixedFileInfo?</p> <p>(A side question: why is your business logic inside the UI? If you had split your logic into a separate function somewhere, you'd probably have a compiling routine that could have served as the base for your question. That might have answered the question in the first place).</p> <p>For questions like yours, I usually take a peek at units in the the <a href="http://jcl.delphi-jedi.org/" rel="nofollow noreferrer">JCL</a> or <a href="http://jvcl.delphi-jedi.org/" rel="nofollow noreferrer">JVCL</a>. They have put a lot of effort in those to be Unicode compatible.</p> <p>Their code that use VerQueryValue is this one in unit JclFileUtils, method VersionFixedFileInfo:</p> <pre><code>// Fixed Version Info routines function VersionFixedFileInfo(const FileName: string; var FixedInfo: TVSFixedFileInfo): Boolean; var Size, FixInfoLen: DWORD; Handle: THandle; Buffer: string; FixInfoBuf: PVSFixedFileInfo; begin Result := False; Size := GetFileVersionInfoSize(PChar(FileName), Handle); if Size &gt; 0 then begin SetLength(Buffer, Size); if GetFileVersionInfo(PChar(FileName), Handle, Size, Pointer(Buffer)) and VerQueryValue(Pointer(Buffer), DirDelimiter, Pointer(FixInfoBuf), FixInfoLen) and (FixInfoLen = SizeOf(TVSFixedFileInfo)) then begin Result := True; FixedInfo := FixInfoBuf^; end; end; end; </code></pre> <p>Hope this gets you started in finding your solution.</p> <p>--jeroen</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload