C ++ Builder - 使用相同的事件TWICE

时间:2017-01-01 18:00:50

标签: c++ events c++builder chess

我遇到了问题,我不明白我哪里出错了。我的程序没有显示任何编译器错误。

我在国际象棋项目工作。当我点击一件时,我想要记住一个ID。当我点击Board时,我想移动带有该ID的文件。我有2个黑色ROOKS,两个都有不同的ID。

以下是代码:

formaJoc.cpp

void movePiece(int piece, int col, int row)
{
    int left = rowColToPixel[col];
    int top  = rowColToPixel[row];
    switch (piece)
    {
        case(0): {
            fJoc->BlackRooks1[1]->imPiece->OnMouseDown = fJoc -> bkRook1MouseDown;
            fJoc->BlackRooks1[1]->imPiece->Left=left;
            fJoc->BlackRooks1[1]->imPiece->Top=top;
            break;
        }
        case(1): {
            fJoc->BlackRooks2[1]->imPiece->OnMouseDown = fJoc -> bkRook2MouseDown;
            fJoc->BlackRooks2[1]->imPiece->Left=left;
            fJoc->BlackRooks2[1]->imPiece->Top=top;
            break;
        }
    }
}

void __fastcall TfJoc::bkRook1MouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y)
{
    id = 0;
}

void __fastcall TfJoc::bkRook2MouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y)
{
    id = 1;
}

void __fastcall TfJoc::imBoardMouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y)
{
    if (id != 99) {
        col = (X - 40) / 36;
        row = (Y - 40) / 36;
        //movePiece(id, col, row);
        //id=99;
        ShowMessage(id);
    }
}

formaJoc.h

bkRook*   BlackRooks1[1];
bkRook*   BlackRooks2[1];

void __fastcall TfJoc::bkRook1MouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall TfJoc::bkRook2MouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y);

void __fastcall imBoardMouseDown(TObject *Sender,
    TMouseButton Button, TShiftState Shift, int X, int Y);

当我运行程序并单击ROOK 1时,ID设置为0.当我点击ROOK 2时,ID仍为0.为什么它不是1?为什么它采用相同的ID?

0 个答案:

没有答案