Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/OBJ Generation    [ Add a report in this area ]  
Report #:  82435   Status: Closed
Unresolved external and a const TMetaclass * parameter
Project:  C++Builder Build #:  14.0.3615.26342
Version:    14.0 Submitted By:   Xavier Portell
Report Type:  Minor failure / Design problem Date Reported:  2/24/2010 6:41:13 AM
Severity:    Commonly encountered problem Last Updated: 4/15/2014 6:18:36 PM
Platform:    All platforms Internal Tracking #:   14478
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE6
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
I am developing a C++ Builder application with RAD Studio 2010. I use Delphi packages that I have compiled with RAD Studio 2010 too. The problem is the following. From C++Builder code I call to functions, procedures or class members of the Delphi package. These wait a class reference (const TMetaClass * in C++) like parameter. When I link the C++Builder application I obtain the linker error: Unresolved external error Function A(const System::TMetaclas * const ) not found. If I remove the keyword const in the Delphi declaration the linker error disappears and the application runs right. I use the __classid keyword to call the funcion:

A( __classid(TMyClass) );

how can I convert a TMetaClass * to a const TMetaClass *?
Steps to Reproduce:
Class definition in Delphi:

unit ClassDef;

interface

type
  TParameterClass = class of TObject;

  TMyClass = class(TObject)
    public
      procedure A(const AClassRef: TParameterClass);
  end;
implementation

procedure TMyClass.A(const AClassRef: TParameterClass);
begin
  //Whatever
end;

end.

Header file with the class delphi declaration:

// CodeGear C++Builder
// Copyright (c) 1995, 2009 by Embarcadero
// All rights reserved

// (DO NOT EDIT: machine generated header) 'Classdef.pas' rev: 21.00

#ifndef ClassdefHPP
#define ClassdefHPP

#pragma delphiheader begin
#pragma option push
#pragma option -w-      // All warnings off
#pragma option -Vx      // Zero-length empty class member functions
#pragma pack(push,8)
#include <System.hpp>
// Pascal unit
#include <Sysinit.hpp>
// Pascal unit

namespace Classdef
{
typedef TMetaClass* TParameterClass;

class DELPHICLASS TMyClass;
class PASCALIMPLEMENTATION TMyClass : public System::TObject
{

typedef System::TObject inherited;


public:

void __fastcall A(const TParameterClass AClassRef);
public:

/* TObject.Create */ inline __fastcall TMyClass(void) : System::TObject() { }

/* TObject.Destroy */ inline __fastcall virtual ~TMyClass(void) { }


};

}
/* namespace Classdef */
using namespace Classdef;
#pragma pack(pop)
#pragma option pop

#pragma delphiheader end.

#endif
// ClassdefHPP

C++ Unit:

#include <vcl.h>
#pragma hdrstop

#include <tchar.h>
#include "ClassDef.hpp"
//----------------------------------------------
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{

TMyClass *Clase = new TMyClass();

Clase->A(__classid(TObject));

delete Clase;


return 0;
}

Error: Checking project dependencies...

Building UnresolvedExternal.cbproj (Debug configuration)

[ILINK32 Error] Error: Unresolved external '__fastcall Classdef::TMyClass::A(const System::TMetaClass * const)' referenced from .\UNRESOLVEDEXTERNAL\DEBUG\CORE.OBJ

[ILINK32 Error] Error: Unable to perform link

Failed

Workarounds
Remove the const keyword in the Delphi class declaration:

Class definition in Delphi:

unit ClassDef;
interface
type
  TParameterClass = class of TObject;
  TMyClass = class(TObject)
    public
      procedure A(AClassRef: TParameterClass);
  end;
implementation

procedure TMyClass.A(AClassRef:TParameterClass);
begin
  //Whatever
end;

end.

how can I convert a TMetaClass * to a const TMetaClass *?
Attachment
None
Comments

None

Server Response from: ETNACODE01