Board index » cppbuilder » Using Vcl components in a non-form based class

Using Vcl components in a non-form based class


2004-09-24 06:57:52 AM
cppbuilder79
Hi all,
I want to use some components that are vcl based
in one of my classes, which is not intended to be form
based at all. However, when i create the object in my
class by calling:
TMMWaveFile *File = new TMMWaveFile();
I get the following error:
Cannot create instance of class TMMWaveFile. TMMWaveFile is abstract...
How can this class possibly be abstract? Since if i am using a form based
application i can just drop the TMMWaveFile component on the form, and it
will compile fine.
If anyone can help that would be great!!
 
 

Re:Using Vcl components in a non-form based class

"Phil Martin" < XXXX@XXXXX.COM >wrote in message
Quote
I get the following error:

Cannot create instance of class TMMWaveFile. TMMWaveFile is abstract...
Please always quote error messages word-for-word. Such an error should be
tell the exact reason why it fails.
Gambit
 

Re:Using Vcl components in a non-form based class

Well the error is calling the WaveFile abstract because it cannot find
certain methods for it that are required to be implemented by one of its
base classes.. I was wondering when you drop a componnet
on a Form are there methods that get defined for that component by
builder that we cannot see in the code. I am not talking about events
but rather methods themselves. Does builder link somewhere else
to find the methods for this component. Since i actually have the source
for TMMWaveFile i can see that it should be abstract because it does
not implement some methods from one of its ancestors.(Hence, that is why i
am getting an error trying to instantiate this object in a non-visual class,
not by
dropping it on a form but by using "new TMMWaveFile(Application")
Or is TMMWaveFile not the actual class that is being implemented when
that component is dropped on a form even though the object inspector shows
that to be the object type in its window, which would mean that there is
some other
class that i have to actually instantiate in my code rather than
TMMWaveFile.
The actual error message was:
[C++ Error] KTC_MPEGEncoder.cpp(20): E2352 Cannot create instance of
abstract class 'TMMWaveFile'
[C++ Error] KTC_MPEGEncoder.cpp(20): E2353 Class 'TMMWaveFile' is abstract
because of '_fastcall
TMMCustomFile::SetTrailingHeader(int) = 0'
So is 'TMMWaveFile' the actual class i should be implementing?
Again if I was using a form builder would add the following to my header
file:
TMMWaveFile *File;
and everything there compiles fine. However if i try to use
TMMWaveFile *File = new TMMWaveFile (Application);
in a non-form based class i get the error described above.
Thankyou.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Phil Martin" < XXXX@XXXXX.COM >wrote in message
news:415354e3$ XXXX@XXXXX.COM ...

>I get the following error:
>
>Cannot create instance of class TMMWaveFile. TMMWaveFile is abstract...

Please always quote error messages word-for-word. Such an error should be
tell the exact reason why it fails.


Gambit


 

{smallsort}

Re:Using Vcl components in a non-form based class

"Phil Martin" < XXXX@XXXXX.COM >wrote in message
Quote
Well the error is calling the WaveFile abstract because it cannot find
certain methods for it that are required to be implemented by one of its
base classes..
What you suggest is not possible. If the component were truely abstract, it
would not be droppable at design-time at all. Components are instantiated
at design-time just as they are at run-time. Abstract classes simply cannot
be instantiated.
Quote
I was wondering when you drop a componnet on a Form are there
methods that get defined for that component by builder that we
cannot see in the code.
No.
Quote
Since i actually have the source for TMMWaveFile i can see
that it should be abstract because it does not implement some
methods from one of its ancestors.
Then TMMWaveFile should not be instantiatable at all.
Quote
Or is TMMWaveFile not the actual class that is being
implemented when that component is dropped on a form
Yes, it is.
Quote
So is 'TMMWaveFile' the actual class i should be implementing?
Yes.
Quote
Again if I was using a form builder would add the following
to my header file:

TMMWaveFile *File;

and everything there compiles fine.
Then it should be compiling fine always.
Quote
However if i try to use

TMMWaveFile *File = new TMMWaveFile (Application);

in a non-form based class i get the error described above.
I suggest you contact MMTools's authors and ask them about it directly.
Gambit
 

Re:Using Vcl components in a non-form based class

Quote
>Well the error is calling the WaveFile abstract because it cannot find
>certain methods for it that are required to be implemented by one of its
>base classes..

What you suggest is not possible. If the component were truely
abstract, it
would not be droppable at design-time at all. Components are
instantiated
at design-time just as they are at run-time. Abstract classes simply
cannot
be instantiated.
I don't believe this to be true, because dropped components are not created
via 'new ' but with one of the VCL Pascal function (IIRC,
'CreateComponent'),
which do not care for abstract classes in a c++ sense.
Torsten
 

Re:Using Vcl components in a non-form based class

"Torsten Franz" <FirstName_LastNameatagilentdottcom>writes:
Quote
>>Well the error is calling the WaveFile abstract because it cannot find
>>certain methods for it that are required to be implemented by one of its
>>base classes..
>
>What you suggest is not possible. If the component were truely
>abstract, it would not be droppable at design-time at all.
>Components are instantiated at design-time just as they are at
>run-time. Abstract classes simply cannot be instantiated.

I don't believe this to be true, because dropped components are not
created via 'new ' but with one of the VCL Pascal function (IIRC,
'CreateComponent'), which do not care for abstract classes in a c++
sense.
Delphi doesn't allow you to directly instantiate abstract classes
though, right?
Besides, you know you can normally instantiate VCL objects with C++'s
new operation, so why should this fail when others succed? I trust
that the compiler is correct, and if the error is reported about
something being abstract either the code really is abstract or it's a
compiler bug. But I don't believe that it would be invalid in C++ but
valid in Delphi to instantiate the same VCL object. That just doesn't
make sense.
--
Chris (TeamB);
 

Re:Using Vcl components in a non-form based class

"Torsten Franz" <FirstName_LastNameatagilentdottcom>wrote in message
Quote
I don't believe this to be true, because dropped components
are not created via 'new ' but with one of the VCL Pascal
function (IIRC, 'CreateComponent'), which do not care for
abstract classes in a c++ sense.
Delphi code doesn't instantiate abstract classes either, and MMTools is
written in Delphi Pascal to begin with.
Gambit
 

Re:Using Vcl components in a non-form based class

Quote
>>>Well the error is calling the WaveFile abstract because it cannot find
>>>certain methods for it that are required to be implemented by one of
>>>its
>>>base classes..
>>
>>What you suggest is not possible. If the component were truely
>>abstract, it would not be droppable at design-time at all.
>>Components are instantiated at design-time just as they are at
>>run-time. Abstract classes simply cannot be instantiated.
>
>I don't believe this to be true, because dropped components are not
>created via 'new ' but with one of the VCL Pascal function (IIRC,
>'CreateComponent'), which do not care for abstract classes in a c++
>sense.

Delphi doesn't allow you to directly instantiate abstract classes
though, right?

Hi Chris,
check this code
//An abstract class
class TMyEdit : public TEdit
{
public:
__fastcall TMyEdit(TComponent* Owner)
: TEdit(Owner)
{}
virtual void AbstractFunc() = 0;
};
//---------------------------------------------------------------------------
//code to demonstrate possible instanciation of this class type
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//1. instanciate via 'new'
//Uncomment next line to get a compiler error (as expected)
//new TMyEdit(this);
//2.Instanciate in a VCL way
//compiles perfectly, but throws at runtime
TMyEdit* p;
Application->CreateForm(__classid(TMyEdit), &p);
p->Parent = this;
p->Visible = true;
//next line results in 'abstract function called' exception
//comment it to see the control working
p->AbstractFunc();
}
So it is possible to inctanciate abstract classes with Pascal specific
functions
Torsten
 

Re:Using Vcl components in a non-form based class

Quote
>I don't believe this to be true, because dropped components
>are not created via 'new ' but with one of the VCL Pascal
>function (IIRC, 'CreateComponent'), which do not care for
>abstract classes in a c++ sense.

Delphi code doesn't instantiate abstract classes either,
Sure it does, check the example I gave Chris in the other branch.
Quote
and MMTools is written in Delphi Pascal to begin with.
I don't see this being relevant.
Torsten