Pb Création évènement OnClick
Bonjour,
Voilà, j'ai créé des boutons afin de les mettre dans une TStringGrid. Chaque bouton est associé à une ligne de la TStringGrid. L'action de tous ces boutons est la même, j'ai donc créé une fontion OnMyButtonClick que j'associe avec chacun des boutons lors de leur création.
Mon problème c'est que l'action ne s'effectue pas lorsqu'on clique sur n'importe lequel des boutons.
Dans mon .h j'ai mis :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| class TForm1 : public TForm
{
__published: // IDE-managed Components
TStringGrid *StringGrid1;
TButton *Button1;
void __fastcall StringGrid1SelectCell(TObject *Sender, int ACol, int ARow,
bool &CanSelect);
void __fastcall MyEditChange(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
//void __fastcall OnMyButtonClick(TObject *Sender);
private:
//void __fastcall WhenKeyPress(TObject *Sender, char &Key);
TButton* MyButton[50];
void __fastcall OnMyButtonClick(TObject *Sender);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
TEdit* __fastcall CreateEdit(TRect R);
TUpDown* __fastcall CreateUpDown(TRect R, int Limite);
TButton* __fastcall CreateButton(TRect R);
void ReInit();
void FillIn(AnsiString Sol, Variant WorksheetSolution);
}; |
Dans mon .cpp, dans une de mes fonctions, je crée les boutons de la manière suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| //Création des champs spéciaux de la TStringGrid
for(int i=IncRepeat ; i<IncCreate ; i++)
{
//Calcul de la position de l'Edit pour l'afficher en dernière colonne
R = StringGrid1->CellRect(4, i+1);
MyEdit[i] = CreateEdit(R);
MyUpDown[i] = CreateUpDown(R,10);
MyUpDown[i]->Associate = MyEdit[i];
R = StringGrid1->CellRect(0, i+1);
MyButton[i] = CreateButton(R);
MyButton[i]->Enabled = true;
MyButton[i]->OnClick = OnMyButtonClick;
//Faire apparaître le TEdit, le TUpDown et le TButton
MyEdit[i]->Show();
MyUpDown[i]->Show();
MyButton[i]->Show();
} |
Voici la fonction de création de mes boutons :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| TButton* __fastcall TForm1::CreateButton(TRect R)
{
TButton *Button = new TButton(StringGrid1);
Button->Visible = false;
Button->Parent = StringGrid1;
Button->Left = R.Left;
Button->Top = R.Top-1;
Button->Width = R.Right - R.Left;
Button->Caption = "Voir";
//Button->OnClick = OnMyButtonClick;
return Button;
} |
Voilà, j'espère avoir été assez clair dans la description de mon problème et que vous avez la réponse ;)