BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using Delphi class functions in CBuilder?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Malte Persike
Guest





PostPosted: Fri May 21, 2004 11:41 am    Post subject: Using Delphi class functions in CBuilder? Reply with quote



Hello everybody,

the last hour I spent with frantically debugging a project in CBuilder6.
The project comprises both Delphi units and c++ source. One of the Delphi
units holds a class which makes use of class functions for a factory
method.

//////////
// TMyObject Delphi Source

TMyObject = class(TObject)
private
FName: string;
public
property Name: string read FName;
class function MakeInfo();
constructor Create(const AName: string); virtual;
end;

constructor TMyObject.Create(const AName: string);
begin
inherited Create;
FName:= AName;
end;

class function TMyObject.MakeInfo();
begin
Result:= Create('Info');
end;


The C++ Source invokes this method directly on the class.

///////////
// Calling the factory method

class TFoo {
public:
void __fastcall DoSomething();
};

void TFoo::DoSomething()
{
TMyObject* obj= TMyObject::MakeInfo(__classid(TMyObject));
...
}

DoSomething works, I can compile into the Delphi source and everything
looks good. But nonetheless obj does not seem to receive a valid
instance. CBuilder at some time raises an Access violation. When I try to
look at obj->Name while debugging the debugger tells me that obj is of
type void.

Can you help me sort out the code?

Kind regards,
Malte

--

The above e-mail address is not valid. To
contact me, please use my real e-mail address:

malte AT t DASH online DOT de
Back to top
OBones
Guest





PostPosted: Fri May 21, 2004 1:31 pm    Post subject: Re: Using Delphi class functions in CBuilder? Reply with quote



Malte Persike wrote:
Quote:
Hello everybody,

the last hour I spent with frantically debugging a project in CBuilder6.
The project comprises both Delphi units and c++ source. One of the Delphi
units holds a class which makes use of class functions for a factory
method.

//////////
// TMyObject Delphi Source

TMyObject = class(TObject)
private
FName: string;
public
property Name: string read FName;
class function MakeInfo();
constructor Create(const AName: string); virtual;
end;

constructor TMyObject.Create(const AName: string);
begin
inherited Create;
FName:= AName;
end;

class function TMyObject.MakeInfo();
begin
Result:= Create('Info');
end;


The C++ Source invokes this method directly on the class.

///////////
// Calling the factory method

class TFoo {
public:
void __fastcall DoSomething();
};

void TFoo::DoSomething()
{
TMyObject* obj= TMyObject::MakeInfo(__classid(TMyObject));
...
}

DoSomething works, I can compile into the Delphi source and everything
looks good. But nonetheless obj does not seem to receive a valid
instance. CBuilder at some time raises an Access violation. When I try to
look at obj->Name while debugging the debugger tells me that obj is of
type void.

Can you help me sort out the code?

Shouldn't your class function have a return type ?

Back to top
Malte Persike
Guest





PostPosted: Fri May 21, 2004 2:13 pm    Post subject: Re: Using Delphi class functions in CBuilder? Reply with quote



OBones <obones_ssspp (AT) gfgdf_meloo (DOT) com> wrote in
news:40ae04c5$1 (AT) newsgroups (DOT) borland.com:

Quote:
Shouldn't your class function have a return type ?

Sorry, you are right. Wrote that code in the newsreader, my "real-life"
code is ok.

But just a few seconds ago I found a solution for the problem. Moving the
Delphi units with class functions to the top position in the project
manager resolves the error. It seems that CBuilder needs to see the
implementation of the class functions in the .pas files before they are
first used anywhere.

Hence, when facing this problem, order the .pas files in the project
manager in such a way that a class method won't be called in a unit
*before* the unit which holds the implemting class. This really is a
matter of the sequence of files in the project manager, not of changing
include/uses order.

Kind regards,
Malte

--

The above e-mail address is not valid. To
contact me, please use my real e-mail address:

malte AT t DASH online DOT de

Back to top
Palle Meinert
Guest





PostPosted: Sat May 22, 2004 3:51 pm    Post subject: Re: Using Delphi class functions in CBuilder? Reply with quote

You should always place your pascal file at top of your project manager
any-way. This is to make sure that the needed *.hpp files are generated and
ajour before they are included by any c++ units.

/Palle


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.