Bonjour,

En ce moment je poste beaucoup lol. Je vous expose mon problème (si on peut appelé cela un problème).

J'ai créer dynamiquement des panels (qui serviront de conteneurs). Chaque panel va contenir des boutons et chaque bouton auront une utilité différente.
Voici un morceau de code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
void __fastcall TFMatch_En_Cours::CreerPalette()
{
int i,Nbre_Nature_Coup,bas,Nb_Liste_Coup,id_nature,Nbr_Total_Coup,Coup;
   AnsiString Libelle_Nature_Coup;
   Coup=0;
   bas=FMatch_En_Cours->ClientHeight;
   TQuery *Nb_Nature_Coup = new TQuery(this);
   Nb_Nature_Coup->DatabaseName="Tennis";
   Nb_Nature_Coup->SQL->Clear();
   Nb_Nature_Coup->SQL->Add("Select count(idT_Nature_Coup) AS Nbre_Nature_Coup From t_nature_coup;");
   Nb_Nature_Coup->Active=true;
   Nbre_Nature_Coup=Nb_Nature_Coup->FieldByName("Nbre_Nature_Coup")->AsInteger;
   TQuery *Requete_Nb_Liste_Coup = new TQuery(this);
   Requete_Nb_Liste_Coup->DatabaseName="Tennis";
   TQuery *Libelle_Nature = new TQuery(this);
   Libelle_Nature->DatabaseName="Tennis";
   for (i=Nbre_Nature_Coup;i>=1;i--)
  {
     Libelle_Nature->SQL->Clear();
     Libelle_Nature->SQL->Add("Select idT_Nature_Coup,S_Libelle From t_nature_coup where idT_Nature_Coup="+AnsiString(i)+";");
     Libelle_Nature->Active=true;
     Libelle_Nature_Coup=Libelle_Nature->FieldByName("S_Libelle")->AsString;
     bas=bas-50;
     TPanel *Panel = new TPanel(this);
     Panel->Parent = this;
     Panel->Anchors <<akLeft <<akBottom;
     Panel->Left=100;
     Panel->Top=bas;
     Panel->Width=300;
     Panel->Height=25;
     Panel->Name = "P" + (AnsiString)i;
     Panel->Caption=Libelle_Nature_Coup;
     id_nature=Libelle_Nature->FieldByName("idT_Nature_Coup")->AsInteger;
     Requete_Nb_Liste_Coup->SQL->Clear();
     Requete_Nb_Liste_Coup->SQL->Add("Select Count(T_Nature_Coup_idT_Nature_Coup) AS Nb_Liste_Coup From t_listecoups where  T_Nature_Coup_idT_Nature_Coup="+(AnsiString)id_nature+";");
     Requete_Nb_Liste_Coup->Active=true;
     Nb_Liste_Coup=Requete_Nb_Liste_Coup->FieldByName("Nb_Liste_Coup")->AsInteger;
     TQuery *Requete_Nbr_Total_Coup = new TQuery(this);
     Requete_Nbr_Total_Coup->DatabaseName="Tennis";
     Requete_Nbr_Total_Coup->SQL->Clear();
     Requete_Nbr_Total_Coup->SQL->Add("Select count(idT_ListeCoups) AS Nbr_Total_Coup From t_listecoups;");
     Requete_Nbr_Total_Coup->Active=true;
     Nbr_Total_Coup=Requete_Nbr_Total_Coup->FieldByName("Nbr_Total_Coup")->AsInteger;
     do
     {
       Coup++;
       Requete_Nb_Liste_Coup->SQL->Clear();
       Requete_Nb_Liste_Coup->SQL->Add("Select (S_Symbole) From t_listecoups Where T_Nature_Coup_idT_Nature_Coup="+(AnsiString)id_nature+";");
       Requete_Nb_Liste_Coup->Active=true;
 
     for (int j=1;j<= Nb_Liste_Coup;j++)
     {
       TButton *Bouton = new TButton(Panel);
       Bouton->Parent = Panel;
       Bouton->Width = 40;
       Bouton->Height = 25;
       Bouton->Left = 0+((40 + 10)*j);
       Bouton->Top=0;
       Bouton->Name="Bouton"+(AnsiString)j;
       Bouton->Caption = Requete_Nb_Liste_Coup->FieldByName("S_Symbole")->AsString;
       Bouton->OnClick = MesBoutonsCodeClick;
       Requete_Nb_Liste_Coup->Next();
     }
     }while (Coup==Nbr_Total_Coup);
  }
}
Voici aussi le code de la fonction MesBoutonsCodeClick
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
void __fastcall TFMatch_En_Cours::MesBoutonsCodeClick(TObject *Sender)
{
 ShowMessage ("ok");
}
et déclaré dans le .h :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
class TFMatch_En_Cours : public TForm
{
__published:	// Composants gérés par l'EDI
       ......
       ......
       ......
        void __fastcall MesBoutonsCodeClick(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
private:	// Déclarations utilisateur
    void __fastcall CreerPalette();
public:		// Déclarations utilisateur
        __fastcall TFMatch_En_Cours(TComponent* Owner);
};
Ce que je souhaite faire dans un premier temps avec la fonction MesBoutonsCodeClick, c'est de pouvoir récupérer le Name du bouton sur lequel j'ai cliqué.

Cantrelle m'a donné une méthode pour savoir les composants créer sur la fiche (merci au passage ) ... ce code est le suivant (code pour des panels) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
void __fastcall TFMatch_En_Cours::Button2Click(TObject *Sender)
{
TPanel *Panel = dynamic_cast < TPanel* > (this->FindComponent("Name_Du_Composant"));
Panel->Caption = "Essai réussi";
}
Voilà, merci d'avoir lu jusque ici lol. J'essaie de faire assez clair ... !
Merci de votre aide!