Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Header Generation    [ Add a report in this area ]  
Report #:  43633   Status: Closed
Some .hpp files will not compile under C++Builder.
Project:  C++Builder Build #:  10.0.2558.35231
Version:    10.0 Submitted By:   Digby Millikan
Report Type:  Basic functionality failure Date Reported:  4/2/2007 4:47:36 AM
Severity:    Critical / Show Stopper Last Updated: 4/2/2007 8:43:43 AM
Platform:    All versions Internal Tracking #:  
Resolution: Test Case Error (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
3.00 out of 5
Total Votes: None
Description
All .hpp files should be compilable by C++Builder. What use is
the file if it can't be used for anything?
Steps to Reproduce:
Try and compile a C++Builder project with the attached .hpp file. The
.pas file which was used to generate this code is also attached.

I have compiled a C++Builder package with a .pas file producing
a .bpi, .bpl and .hpp file, and then installed it.
When I compile my C++Builder project I get a compile error in the
package .hpp file;

[C++ Error] Xlsfile.hpp(744): E2238 Multiple declaration for '_fastcall
ETokenException::ETokenException(int)'
[C++ Error] Xlsfile.hpp(737): E2344 Earlier declaration of '_fastcall
ETokenException::ETokenException(int)''

The .hpp code is as follows;

public:
__fastcall ETokenException(int Token);
__property int Token = {read=FToken, nodefault};
public:
#pragma option push -w-inl
/* Exception.CreateFmt */ inline __fastcall ETokenException(const
AnsiString Msg, System::TVarRec const * Args, const int Args_Size) :
Sysutils::Exception(Msg, Args, Args_Size) { }
#pragma option pop
#pragma option push -w-inl
/* Exception.CreateRes */ inline __fastcall ETokenException(int Ident)/*
overload */ : Sysutils::Exception(Ident) { }
#pragma option pop
#pragma option push -w-inl

Here is the pascal code which generates this problem .hpp file;

  ETokenException = class(Exception)
  private
    FToken: integer;
  public
    constructor Create(Token: integer);
    property Token: integer read FToken;
  end;

{ ETokenException }

constructor ETokenException.Create(Token: integer);
begin
  FToken := Token;
  inherited CreateFmt(sBadToken, [FToken]);
end;

In the .hpp file you have two constructors with the same name and
the same signature. You can't do that in C++.  The compiler won't
know which one to use. In Delphi, multiple constructors in a class
can have different names. So it is possible to have different constructors
with the same signature.  In C++, however, constructors must have the
same name as the class. So when translating Delphi to C++, all of the
Delphi constructors get renamed to the class name.            

Workarounds
None
Attachment
None
Comments

Leo Siefert at 4/2/2007 8:45:32 AM -
Can you attach a compilable delphi project using the code you included? I am unable to figure out how to use the delphi code without errors.

After reading Gambit's responses to your post in the cppbuilder.language.cpp newsgroup, I have closed this as a Test Case Error". If you find that the information he posted was not the solution to your problem you can reopen the report by modifying the steps.

Digby Millikan at 12/4/2007 12:04:38 AM -
My test case was from a third party component. It is a failry common problem that components written in delphi, but also marketed for C++Builder do not install in C++Builder because when generate all C++Builder files is checked the .hpp files generated will not compile. The projects compile in delphi but not in C++Builder. I have had this occur three times from major international component retailers. Each time I just get the component retailer to modify their pascal code to  produce error free .hpp files. I'll organise representative test cases, so each incompatibility can be addressed one at a time.

Leo Siefert at 12/4/2007 5:43:09 AM -
>I'll organise representative test cases, so each incompatibility can be addressed one at a time.

That's definitely the approach to take. A general report such as this will probably never be opened unless you do change it to reflect a single type of hpp file generation error.

Note that there are already some reports filed trying to get better hpp generation, so before you work too hard on a specific type of error you might want to do a search to be sure it has not already been reported.

Note also, that due to differences between the Delphi and C++ languages it will not be possible to ever guarantee that all delphi code can be accessed by legal C++ header files and function as it does in Delphi. This meanse that it will always be the responsibility of the Delphi programmer to make sure that the Delphi code is C++ compatible. The only way to change this would be to change the Delphi language in ways that would make much esisting code obsolete.

Meanwhile, there is still clearly much that can be done to improve the situation.

Server Response from: ETNACODE01