C++ Builder - Piece.cpp(20): E2316 'Button1Click' is not a member of 'TForm'

1.3k Views Asked by At

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'

1

There are 1 best solutions below

3
On

Look very carefully at your Piece() code. It has its own fJoc input parameter that is of type TForm*. When it tries to access fJoc->Move, and compiler complains:

'Move' is not a member of 'TForm'

And that error is correct. The TForm class does not have a member named Move. Move is actually a member of your TfJoc class instead.

So, you need to either

  1. change the input parameter to TfJoc* instead of TForm*

  2. just get rid of the input parameter altogether and use the global fJoc pointer that is declared in formaJoc.h (assuming your TfJoc object is auto-created at program startup).