Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 381545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:05:45+00:00 2026-05-12T15:05:45+00:00

I have some code that compiles fine with D7 but fails with D2010. Obviously

  • 0

I have some code that compiles fine with D7 but fails with D2010.
Obviously it is an Unicode issue:

The compile error is:
E2251 Ambiguous overloaded call to ‘StrPas’

Here is the whole procedure:

procedure GetVersionInfo;
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;
  DataLen: LongWord;
  LangCharSetInfo: PLangCharSetInfo;
  LangCharSetString: string;
begin
  LabelComments.Caption := 'No version information for this program is available!';
  {Get size and allocate buffer for VerInfo}
  if GetModuleFileName(hInstance, FileName, SizeOf(FileName)) > 0 then
  begin
    Size := GetFileVersionInfoSize(FileName, VerHandle);
    if Size > 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);
            if VerQueryValue(Buffer, StrPCopy(SubBlock, '\StringFileInfo\' + LangCharSetString + '\ProductName'), Data, DataLen) then
            begin
              LabelProductName.Caption := StrPas(Data);
              Caption := LabelProductName.Caption;
            end;
            if VerQueryValue(Buffer, StrPCopy(SubBlock, '\StringFileInfo\' + LangCharSetString + '\FileVersion'), Data, DataLen) then
              LabelVersion.Caption := StrPas(Data);
            if VerQueryValue(Buffer, StrPCopy(SubBlock, '\StringFileInfo\' + LangCharSetString + '\LegalCopyright'), Data, DataLen) then
              LabelCopyright.Caption := StrPas(Data);
            if VerQueryValue(Buffer, StrPCopy(SubBlock, '\StringFileInfo\' + LangCharSetString + '\Comments'), Data, DataLen) then
              LabelComments.Caption := StrPas(Data);
          end;
        end;
      finally
        FreeMem(Buffer, Size);
      end;
    end
  end;
end;

The doc for StrPas says

function StrPas(const Str: PAnsiChar): AnsiString; overload;

This function is provided fasor backwards compatibility only.
To convert a null-terminated string to an AnsiString or native
Delphi language string, use a typecast or an signment.

So the question is should I remove all calls to StrPas ?
The only way I make this to compile is to do a hardcast to PAnsi char like:

LabelProductName.Caption := StrPas(PAnsiChar(Data));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:05:46+00:00Added an answer on May 12, 2026 at 3:05 pm

    You edited your question with a full compiling sample. Good!

    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.

    Then your business logic would become something like this:

    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)) > 0 then
      begin
        Size := GetFileVersionInfoSize(FileName, VerHandle);
        if Size > 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;
    

    And in the UI, you will need to call your business logic, and put the results into the various controls.

    –jeroen

    Answer before edit:

    Your code does not compile as is, so without more context, it is hard to answer your quest.

    What are the data types of Buffer, SubBlock, LongCharSetString and DataLen? How did you obtain Buffer?

    Is Data really meant to be a Pointer to (Ansi or Unicode) characters? Shouldn’t it ultimately be of pointing to PVSFixedFileInfo?

    (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).

    For questions like yours, I usually take a peek at units in the the JCL or JVCL. They have put a lot of effort in those to be Unicode compatible.

    Their code that use VerQueryValue is this one in unit JclFileUtils, method VersionFixedFileInfo:

    // 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 > 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;
    

    Hope this gets you started in finding your solution.

    –jeroen

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 183k
  • Answers 183k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Compare A to B and C to D. WLOG, suppose… May 12, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer You shouldn't rely on Stream.Length, its possible it could be… May 12, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html There is no 'one size fits all' - you… May 12, 2026 at 4:39 pm

Related Questions

I am new to Windows and Visual Studio. I have a strong background in
I have started working on some code left behind by previous developers, and I'm
I have an iPhone app that compiles and runs fine in the Simulator on
Ok, I wrote this question up earlier today but I decided to delete it
I have two workflow foundation (.NET 3.5 SP 1) application which compiles fine. It

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.