2016-12-31 42 views
1

我必須爲我的OOP課程在C-builder中製作一個國際象棋程序。 (面向對象編程)C++ Builder - Piece.cpp(20):E2316'Button1Click'不是'TForm'的成員

我做了一個類Piece,並在這個類中創建了一個TImage imPiece。現在我想用一個來自主類的函數爲這個圖像分配一個Event OnClick。

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 */ 
}; 

錯誤:

[C++ Error] Piece.cpp(20): E2316 'Move' is not a member of 'TForm'

+1

請勿將圖像或鏈接發佈到圖像。發佈實際的代碼和實際的錯誤消息。有關錯誤消息的內容尚不清楚? Tform沒有這樣的成員。 – Unimportant

+1

請不要在評論中發佈代碼。 **編輯**你的文章的代碼。 –

+0

@ user1320881我想從我創建的類創建一個TImage事件,並使用c-builder類中的函數。 –

回答

1

仔細查看您的Piece()代碼。它有自己的fJoc輸入參數,其類型爲TForm*。當它試圖訪問fJoc->Move,並且編譯器抱怨:

'Move' is not a member of 'TForm'

並且該錯誤是正確的。 TForm類沒有名爲Move的成員。 Move實際上是您的TfJoc類的成員。

所以,你需要或者

  1. 變化的輸入參數的TfJoc*代替TForm*

  2. 一下就完全擺脫了輸入參數,並使用在formaJoc.h宣佈全球fJoc指針(假設你的TfJoc對象是在程序啓動時自動創建的)。

+0

如何更改輸入參數?我只在TfJoc類中有TForm:public TForm。 –

+0

我將所有TForm重命名爲TfJoc,顯然現在它的工作。現在我只需要弄清楚如何讓棋子隨機移動。我用每個座標得到每件作品。 –

+0

@ Anton-CristianMocanu這是一個單獨的問題,[你已經問過](http://stackoverflow.com/questions/41411091/)。 –