0

I use VerQueryValue() to get the value of the "PrivateBuild" key and this works fine.

Except when the value is only one character: e.g. 'b' which is not unusual for a beta-version. In that case the function returns False.

I've also tested this with a 3rd party Delphi program that can read file-version (to make sure, that my file-reading logic is not the problem):

http://www.delphidabbler.com/articles?article=20

this has the same problem.

Can anyone verify that this is a problem with the Windows function VerQueryValue()? It could also be a problem of the Delphi XE3 IDE - maybe it has a bug and does not write the single character into the dll file-version info.

4
  • There is no problem with VarQueryValue. It works as intended. There is no problem with the header translation in XE3. It is accurate. The problem must be your expectations, or your code that calls VarQueryValue. Unfortunately you did not show that. You've accepted an answer that appears to me to be factually erroneous. Jun 28, 2013 at 9:12
  • Or the problem is that Delphi generates a bogus resource. Jun 28, 2013 at 11:15
  • I did not post code, because a full-blown well-explained and maintained sample exists. I've added a link to it. So what is the point in re-posting lots of code-lines, when anyone can just download a full working example?
    – TmTron
    Jul 4, 2013 at 7:20
  • Links go stale over time. Here we like questions to be as standalone as possible. A short SSCCE is always good. Jul 4, 2013 at 7:30

1 Answer 1

1

I can confirm this is a problem in XE3 & 4. It appears to be an issue between the W (Unicode) version and the A (ANSI) versions, as the same code in Delphi 2007 I used to test XE3 & 4 correctly reads a single character PrivateBuild value. As @DavidHeffernan mentions in the comments, this could be an issue with the resource compiler, although I'm not sure that the 32-bit resource compiler has changed between D2007 and XE. (Using a resource with a language ID that required Unicode and then Unicode values works in D2007, so that resource compiler version supports Unicode as well as Ansi.)

The test code, grabbed quickly from an old unit I had sitting around, added to the implementation section of a new VCL Forms Application with a TMemo and TButton on it, and quickly setting up test version info using the normal Delphi dialogs:

type
  TVersionInfo=record
    // Name of company
    CompanyName: string;
    // Description of file
    FileDescription: string;
    // File version
    FileVersion: string;
    // Internal name
    InternalName: string;
    // Legal copyright information
    LegalCopyright: string;
    // Legal trademark information
    LegalTradeMarks: string;
    // Original filename
    OriginalFilename: string;
    // Product name
    ProductName : string;
    // Product version
    ProductVersion: string;
    // Private build
    PrivateBuild: string;
    // Comments
    Comments: string;
  end;

const
  ItemList: array [0..10] of string = ( 'CompanyName',
                                       'FileDescription',
                                       'FileVersion',
                                       'InternalName',
                                       'LegalCopyright',
                                       'LegalTradeMarks',
                                       'OriginalFilename',
                                       'ProductName',
                                       'ProductVersion',
                                       'PrivateBuild',
                                       'Comments' );

function GetVerInfo(const FileName: string; var VersionInfo: TVersionInfo): Boolean;
var
  i: Integer;
  dwLen: Word;
  lpdwHandle: Cardinal;
  pValue: PChar;
  lpData: Pointer;
  uiLen: UInt;
  LCID: string;
begin
  dwLen := GetFileVersionInfoSize(PChar(FileName), lpdwHandle);
  Result := (dwLen > 0);
  if not Result then
    Exit;
  GetMem(lpData, (dwLen + 1) * SizeOf(Char));
  try
    LCID := 'StringFileInfo\' + IntToHex(GetUserDefaultLCID, 4) + IntToHex(GetACP, 4) + '\';

    GetFileVersionInfo(PChar(FileName), 0, dwLen, lpData);
    for i := Low(ItemList) to High(ItemList) do
    begin
      if (VerQueryValue(lpData, PChar(LCID + ItemList[i]), Pointer(pValue), uiLen)) then
        case i of
          0: VersionInfo.CompanyName := pValue;
          1: VersionInfo.FileDescription := pValue;
          2: VersionInfo.FileVersion := pValue;
          3: VersionInfo.InternalName := pValue;
          4: VersionInfo.LegalCopyright := pValue;
          5: VersionInfo.LegalTradeMarks := pValue;
          6: VersionInfo.OriginalFilename := pValue;
          7: VersionInfo.ProductName := pValue;
          8: VersionInfo.ProductVersion := pValue;
          9: VersionInfo.PrivateBuild := pValue;
         10: VersionInfo.Comments := pValue;
        end;

    end;
  finally
    FreeMem(lpData);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  VI: TVersionInfo;
begin
  Memo1.Clear;
  GetVerInfo(ParamStr(0), VI);
  Memo1.Lines.Add('Company name: ' + VI.CompanyName);
  Memo1.Lines.Add('File version: ' + VI.FileVersion);
  Memo1.Lines.Add('Private build: ' + VI.PrivateBuild);

end;
7
  • This is not right. There's nothing wrong with the header translation in any version of Delphi that I can see. Jun 28, 2013 at 9:10
  • @David, where did I say there was? I said I tested this code and was able to reproduce what the poster was seeing in XE3 & 4. What part of that says "there's something wrong with the header translation"? I said there appears to be a difference between the W and A versions, but where did I say that was Delphi's fault?
    – Ken White
    Jun 28, 2013 at 10:51
  • "I can confirm this is a problem in XE3 & 4". I took that to mean that there is a problem in Delphi. Could you be more precise as to what exactly the problem is? Jun 28, 2013 at 10:54
  • The problem is that, using the code I posted, a single-character value for PrivateBuild can't be read, and making the PrivateBuild a two-character value it works fine, just as the original question says. I posted my code, which has been use for several years successfully, and which I used to test it as described in my answer. The problem can be duplicated in XE3 and XE4, but the code is fine in D2007 (again, as I stated in my answer). I posted the code so that others could see if it was my mistake (or use it to test also).
    – Ken White
    Jun 28, 2013 at 11:02
  • You cannot retrieve a single-character PrivateBuild version value in XE3 or XE4 (eg., 'b'), while a value of 'b1' or '1b' can be read. Delphi 2007, using the same exact code, reads either of them correctly. I don't know what's wrong either, and didn't say I did. I said I could reproduce the problem, which is what the poster asked. I'm not sure what's unclear there.
    – Ken White
    Jun 28, 2013 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.