Board index » cppbuilder » new Component from a non derived class

new Component from a non derived class


2003-07-13 02:51:48 AM
cppbuilder12
I am trying to create a new Fastnet TNMHTTP from a class that I have
written.
The constructor must take parameters TNMHTTP(TComponent * AOwner);
My class does not derive from TComponent so the only way I can create it is
by passing a pointer from Form1 to the constructor.
TNMHTTP(pForm1);
Form1 creates a new MyClass and MyClass creates new TNMHTTP.
Why does TNMHTTP need a pointer to a TComponent in its constructor?
Passing a pointer to the TNMHTTP contructor that points to Form1 seems
pointless (does not do anything).
Is there any way to create a new TNMHTTP without passing a pointer that
points to a TComponent?
If I derive MyClass from TComponent it shows a compile error:
cannot find default constructor to initialise base class 'TComponent'.
Can anyone advise me of the best solution.
Thanks
James
 
 

Re:new Component from a non derived class

"James Diskwave" <james at diskwave dot com>wrote:
Quote
I am trying to create a new Fastnet TNMHTTP from a class
that I have written.
You might try the .writting group to get a better response.
Quote
Why does TNMHTTP need a pointer to a TComponent in its
constructor?
I'm guessing because all components are derived from TComponent.
~ JD
 

Re:new Component from a non derived class

James Diskwave wrote:
Quote
Is there any way to create a new TNMHTTP without passing a pointer that
points to a TComponent?
Did you try
TNMHTTP *NMHTTP = new TNMHTTP ( NULL );
Quote
If I derive MyClass from TComponent it shows a compile error:
cannot find default constructor to initialise base class 'TComponent'.
If you have
class TMyComponent : public TComponent
{
public:
__fastcall TMyComponent(TComponent* Owner);
};
then the constructer looks like
__fastcall TMyComponent::TMyComponent (TComponent *Owner) :
TComponent ( Owner )
{
}
But if you write:
__fastcall TMyComponent::TMyComponent (TComponent *Owner)
{
// [C++Error] :
// Cannot find default constructor to initialize
// base class 'Classes::TComponent'.
}
Hans.
 

{smallsort}