I have to make a chess program in C-builder for my OOP course. (object oriented programming)
I made a class Piece and created, inside this class, a TImage imPiece. Now I want to assign this image an Event OnClick using a function from the main class.
Piece.cpp
Piece::Piece(unsigned int, unsigned int, TForm* fJoc)
{
imPiece = new TImage(fJoc);
imPiece -> Parent = fJoc;
imPiece -> Stretch = true;
imPiece -> Transparent = true;
imPiece -> Visible = true;
imPiece -> Width = 36;
imPiece -> Height = 36;
imPiece -> OnClick = fJoc -> Move;
}
Piece::~Piece(){}
formaJoc.cpp
void __fastcall TfJoc::Move(TObject *Sender)
{
exit(0);
}
formaJoc.h
class TfJoc : public TForm
{
/* ... not quoted parts of class declaration */
void __fastcall Move(TObject *Sender);
/* ... not quoted parts of class declaration */
};
Error:
[C++ Error] Piece.cpp(20): E2316 'Move' is not a member of 'TForm'
Look very carefully at your
Piece()
code. It has its ownfJoc
input parameter that is of typeTForm*
. When it tries to accessfJoc->Move
, and compiler complains:And that error is correct. The
TForm
class does not have a member namedMove
.Move
is actually a member of yourTfJoc
class instead.So, you need to either
change the input parameter to
TfJoc*
instead ofTForm*
just get rid of the input parameter altogether and use the global
fJoc
pointer that is declared informaJoc.h
(assuming yourTfJoc
object is auto-created at program startup).