IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

Modifier plusieurs composants dans une boucle


Sujet :

C++Builder

  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 132
    Par défaut Modifier plusieurs composants dans une boucle
    Bonsoir,

    Ce code fonctionne avec la VCL et sert à modifier plusieurs composants.

    Existe t-il un code analogue avec FireMonkey ?

    Merci d'avance.

    Cordialement.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        for ( int x=0 ; x<ControlCount ; x++)
             if ((AnsiString)Controls[x]->ClassName() == "TEdit" )
                      ((TEdit*)Controls[x])->Text = "Ok";
    }

  2. #2
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par défaut
    Salut Via une méthode alternative
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    	TComponent* theComponent;
    	for (int n=0;n<ComponentCount;n++)
    	{
    	 theComponent=Components[n];
    	 Memo1->Lines->Add(theComponent->Name);
    	}
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  3. #3
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 132
    Par défaut
    Salut DjmSoftware et merci pour tes réponses.

    Je crée un jeu de 104 cartes en c++ builder starter FireMonkey.
    Une carte = une NewImage créée avec TImage et TBitmap
    La boucle avec TComponent* marche.
    J'ai écrit ce code (grâce à ton info) pour éviter d'avoir une multitude de fonctions.
    C'est à dire une fonction onmousedown, onmouvemove, etc ... pour chaque carte créée.
    Le problème est que je n'arrive pas à différencier les cartes dans les foncions Onmousedown, Onmousemove ...
    Chaque fois que je clique sur une carte pour la déplacer, toutes les cartes se déplacent ensemble. Ce qui paraît logique.
    Est-il possible de rendre chaque carte autonome au sein d'une même fonction en sachant que cette fonction concerne 104 cartes ?
    Ci-dessous mon code.

    Cordialement.



    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
     
    // unit.h
    public:		// Déclarations utilisateur
    	__fastcall TTapis(TComponent* Owner);
     
    	  TBitmap *MyBitmap;   // pour créer les BitMap
              TComponent* theComponent;
    	  bool Deplacement;   // pour déplacer les cartes avec OnmouseMove
    	  int XPos, YPos; 
     
    	  void __fastcall CarteDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y);
    	  void __fastcall CarteLeave(TObject *Sender);
    	  void __fastcall CarteMove(TObject *Sender, TShiftState Shift, float X,
    		  float Y);
    	  void __fastcall CarteUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y);
     
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TTapis *Tapis;
    //---------------------------------------------------------------------------
     
    struct jeudecartes
    {
      TImage *NewImage;
      int numero;  // numéro de la carte
    };
     
    #endif
     
    //***********************************************
    // unit .cpp
     
    jeudecartes carte[104];   //  tableau avec struct jeudecartes
     
     
     
     
    void __fastcall TTapis::Button1Click(TObject *Sender)
    {
    // création des cartes issues de Timage et Tbimap avec imagelist et glyph
    for (int i = 0; i < 104; i++)
     {
      Glyph1->ImageIndex =i;
      MyBitmap = new TBitmap(0,0);
      MyBitmap->Assign(Glyph1->MakeScreenshot());
      carte[i].NewImage = new TImage(this); // this est Form1 à cause de TTapis:
      carte[i].NewImage->Parent = Tapis; // ou NewImage[i]->Parent = this;
      carte[i].NewImage->Bitmap = MyBitmap;
      carte[i].numero = i; //numérote la carte
      }
     
    // Pour éviter 4 fonctions par cartes
     for (int n=0;n<ComponentCount;n++)
    	{
    	 theComponent=Components[n];
     
    	 if (theComponent->ClassName()== "TImage")
    	   ((TImage*)Components[n])->OnMouseDown = CarteDown;
     
    	 if (theComponent->ClassName()== "TImage")
    	   ((TImage*)Components[n])->OnMouseLeave = CarteLeave;
     
    	 if (theComponent->ClassName()== "TImage")
    	   ((TImage*)Components[n])->OnMouseMove = CarteMove;
     
    	 if (theComponent->ClassName()== "TImage")
    	   ((TImage*)Components[n])->OnMouseUp = CarteUp;
    	}
    // affichage de quelques cartes pour essai
     
    		 carte[0].NewImage->Position->X = 500;
    		 carte[0].NewImage->Position->Y = 500;
     
    		 carte[1].NewImage->Position->X = 800;
    		 carte[1].NewImage->Position->Y = 500;
     
    		 carte[2].NewImage->Position->X = 1100;
    		 carte[2].NewImage->Position->Y = 500;
     
     
    }
     
    void __fastcall TTapis::CarteDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y)
    {
     		  XPos = X;
    		  YPos = Y;                
     
       if (Shift.Contains(ssLeft)) Deplacement = true;
    }
     
    void __fastcall TTapis::CarteMove(TObject *Sender, TShiftState Shift, float X,
    		  float Y)
     
    // toutes les cartes se déplacent ensemble. J'ai essayé plusieurs combinaisons, rien à faire
    {
    	if (Deplacement == true)
    	{
    	 for (int i = 0; i < 104; i++)
    	  {
    		if (carte[i].numero == 0)
    		    {
    		    carte[0].NewImage->Position->X += X-XPos;
    		    carte[0].NewImage->Position->Y += Y-YPos;
    		    }
    		if (carte[i].numero == 1)
    		    {
    		    carte[1].NewImage->Position->X += X-XPos;
    		    carte[1].NewImage->Position->Y += Y-YPos;
    		    }
    	  }
       }
    }
     
    void __fastcall TTapis::CarteUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y)
     
    {
     Deplacement = false;
    }

  4. #4
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par magdani Voir le message
    Salut DjmSoftware et merci pour tes réponses.

    Je crée un jeu de 104 cartes en c++ builder starter FireMonkey.
    Une carte = une NewImage créée avec TImage et TBitmap
    La boucle avec TComponent* marche.
    J'ai écrit ce code (grâce à ton info) pour éviter d'avoir une multitude de fonctions.
    C'est à dire une fonction onmousedown, onmouvemove, etc ... pour chaque carte créée.
    Le problème est que je n'arrive pas à différencier les cartes dans les foncions Onmousedown, Onmousemove ...
    Chaque fois que je clique sur une carte pour la déplacer, toutes les cartes se déplacent ensemble. Ce qui paraît logique.
    Est-il possible de rendre chaque carte autonome au sein d'une même fonction en sachant que cette fonction concerne 104 cartes ?
    Ci-dessous mon code.

    Bien cordialement.
    Salut Tu te complique la vie
    Un object FMX.Objects.TImage dispose de 2 propriétés interessantes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Tag // Stocke une valeur entière NativeInt comme partie d'un composant.
    TagString // Propriété personnalisée qui stocke toute valeur de chaîne.
    tu peux donc différencier tes cartes via ces propriétés
    par ailleurs il est fortement déconseillé d'utiliser des tableaux statiques avec des objets VCL ou FMX utilise plutôt des Tlist ou les containers de la std
    lors de la création de ton onject Timage du peux assigner directement le même traitement OnOnMouseDown , etc
    dans le traitement conmun de OnOnMouseDown , .... tu peux différencier très simplement tes cartes via leur propriété Tag

    encore quelques petites choses à corriger

    cdlt

    ci-dessous le lien vers l'aide d'embarcadero http://docwiki.embarcadero.com/Libraries/Tokyo/fr/FMX









    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
     
    // unit.h
    public:        // Déclarations utilisateur
        __fastcall TTapis(TComponent* Owner);
     
          TBitmap *MyBitmap;   // pour créer les BitMap
              TComponent* theComponent;
          bool Deplacement;   // pour déplacer les cartes avec OnmouseMove
          int XPos, YPos; 
     
          void __fastcall CarteDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
              float X, float Y);
          void __fastcall CarteLeave(TObject *Sender);
          void __fastcall CarteMove(TObject *Sender, TShiftState Shift, float X,
              float Y);
          void __fastcall CarteUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
              float X, float Y);
     
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TTapis *Tapis;
    //---------------------------------------------------------------------------
     
    struct jeudecartes
    {
      TImage *NewImage;
      int numero;  // numéro de la carte
    };
     
    #endif
     
    //***********************************************
    // unit .cpp
     
    jeudecartes carte[104];   //  tableau avec struct jeudecartes
     
     
     
     
    void __fastcall TTapis::Button1Click(TObject *Sender)
    {
    // création des cartes issues de Timage et Tbimap avec imagelist et glyph
    for (int i = 0; i < 104; i++)
     {
      Glyph1->ImageIndex =i;
      MyBitmap = new TBitmap(0,0);
      MyBitmap->Assign(Glyph1->MakeScreenshot());
      carte[i].NewImage = new TImage(this); // this est Form1 à cause de TTapis:
      carte[i].NewImage->Parent = Tapis; // ou NewImage[i]->Parent = this;
      carte[i].NewImage->Bitmap = MyBitmap;
      carte[i].numero = i; //numérote la carte
      }
     
    // Pour éviter 4 fonctions par cartes
     for (int n=0;n<ComponentCount;n++)
        {
         theComponent=Components[n];
     
         if (theComponent->ClassName()== "TImage")
           ((TImage*)Components[n])->OnMouseDown = CarteDown;
     
         if (theComponent->ClassName()== "TImage")
           ((TImage*)Components[n])->OnMouseLeave = CarteLeave;
     
         if (theComponent->ClassName()== "TImage")
           ((TImage*)Components[n])->OnMouseMove = CarteMove;
     
         if (theComponent->ClassName()== "TImage")
           ((TImage*)Components[n])->OnMouseUp = CarteUp;
        }
    // affichage de quelques cartes pour essai
     
             carte[0].NewImage->Position->X = 500;
             carte[0].NewImage->Position->Y = 500;
     
             carte[1].NewImage->Position->X = 800;
             carte[1].NewImage->Position->Y = 500;
     
             carte[2].NewImage->Position->X = 1100;
             carte[2].NewImage->Position->Y = 500;
     
     
    }
     
    void __fastcall TTapis::CarteDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
              float X, float Y)
    {
               XPos = X;
              YPos = Y;                
     
       if (Shift.Contains(ssLeft)) Deplacement = true;
    }
     
    void __fastcall TTapis::CarteMove(TObject *Sender, TShiftState Shift, float X,
              float Y)
     
    // toutes les cartes se déplacent ensemble. J'ai essayé plusieurs combinaisons, rien à faire
    {
        if (Deplacement == true)
        {
         for (int i = 0; i < 104; i++)
          {
            if (carte[i].numero == 0)
                {
                carte[0].NewImage->Position->X += X-XPos;
                carte[0].NewImage->Position->Y += Y-YPos;
                }
            if (carte[i].numero == 1)
                {
                carte[1].NewImage->Position->X += X-XPos;
                carte[1].NewImage->Position->Y += Y-YPos;
                }
          }
       }
    }
     
    void __fastcall TTapis::CarteUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
              float X, float Y)
     
    {
     Deplacement = false;
    }
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  5. #5
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 132
    Par défaut
    Bonjour DJMSoftware et merci pour tes réponses.

    Effectivement, tag est bien pratique pour différencier les objets.
    J'ai essayé plusieurs combinaisons pour déplacer une carte, rien à faire, les onmouse ... agissent sur toutes les cartes.
    Je cherche également à utiliser un conteneur vector ou list. Je maîtrise pour les conteneurs avec int, double, char, string ... mais avec les objets,
    c'est plus compliqué. vector<TImage> carte;

    Cordialement.



    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
     
    for (int i = 0; i < 104; i++)
     {
      Glyph1->ImageIndex =i;
      MyBitmap = new TBitmap(0,0);
      MyBitmap->Assign(Glyph1->MakeScreenshot());
      carte[i].NewImage = new TImage(this); // this est Form1 à cause de TTapis:
      carte[i].NewImage->Parent = Tapis; // ou NewImage[i]->Parent = this;
      carte[i].NewImage->Bitmap = MyBitmap;
      carte[i].NewImage->OnMouseDown =  CarteDown;
      carte[i].NewImage->OnMouseLeave = CarteLeave;
      carte[i].NewImage->OnMouseMove = CarteMove;
      carte[i].NewImage->OnMouseUp = CarteUp;
      carte[i].NewImage->Tag = i;
      carte[i].NewImage->Height = Glyph1->Height;
      carte[i].NewImage->Width = Glyph1->Width;
      carte[i].NewImage->Cursor = crHandPoint;
      //
     }
    void __fastcall TTapis::CarteDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y)
    {
       if (carte[0].NewImage->Tag == 0)
    			   {
    			   XPos = X;
    			   YPos = Y;
    			   AncienX = carte[0].NewImage->Position->X;
    			   AncienY = carte[0].NewImage->Position->Y;
    			   }
    	if (carte[1].NewImage->Tag == 1)
    			   {
    			   XPos = X;
    			   YPos = Y;
    			   AncienX = carte[1].NewImage->Position->X;
    			   AncienY = carte[1].NewImage->Position->Y;
    			   }
     
       if (Shift.Contains(ssLeft)) Deplacement = true;
    }
    void __fastcall TTapis::CarteMove(TObject *Sender, TShiftState Shift, float X,
    		  float Y)
    {
    	if (Deplacement == true)
    	{
    	  if (carte[0].NewImage->Tag == 0)
    		 {
    		  carte[0].NewImage->Position->X += X-XPos;
    		  carte[0].NewImage->Position->Y += Y-YPos;
    		 }
          if (carte[1].NewImage->Tag == 1)
    		 {
    		  carte[1].NewImage->Position->X += X-XPos;
    		  carte[1].NewImage->Position->Y += Y-YPos;
    		 }
    	}
    }

  6. #6
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par défaut
    Salut,
    Ci-dessous un petit exemple pour t'aider
    je crée une carte sous la forme d'un TPanel par l'appui sur un bouton
    le propriétaire de(des)cartes est la Form elle même, qui se chargera automatiquement de tous les composants qui la forme
    La propriété Tag te permet simplement de déterminer la carte.
    le 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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
     
    //.dfm
    object Form87: TForm87
      Left = 0
      Top = 0
      Caption = 'Form87'
      ClientHeight = 299
      ClientWidth = 635
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object StatusBar1: TStatusBar
        Left = 0
        Top = 280
        Width = 635
        Height = 19
        Panels = <
          item
            Text = 'Carte Gauche:'
            Width = 80
          end
          item
            Width = 50
          end
          item
            Text = 'CarteHaut'
            Width = 80
          end
          item
            Width = 50
          end
          item
            Text = 'Carte'
            Width = 80
          end
          item
            Width = 50
          end>
        ExplicitLeft = 288
        ExplicitTop = 288
        ExplicitWidth = 0
      end
      object Button1: TButton
        Left = 264
        Top = 249
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 1
        OnClick = Button1Click
      end
    end
     
     
    //le .h
    //---------------------------------------------------------------------------
     
    #ifndef Unit87H
    #define Unit87H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <ExtCtrls.hpp>
    #include <ComCtrls.hpp>
    //---------------------------------------------------------------------------
    class TForm87 : public TForm
    {
    __published:	// Composants gérés par l'EDI
    	TStatusBar *StatusBar1;
    	TButton *Button1;
    	void __fastcall Button1Click(TObject *Sender);
     
    private:	// Déclarations utilisateur
    	void __fastcall SendToStatusPanel(int x, int y,int Elem);
        void __fastcall EMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
              int X, int Y);
    	void __fastcall EMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
              int X, int Y);
    	void __fastcall EMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
    	bool MouseBtnPressed;
    	int CarteNr;
    	int PWight;
    public:		// Déclarations utilisateur
    	__fastcall TForm87(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm87 *Form87;
    //---------------------------------------------------------------------------
    #endif
     
     
    //le code
     
    // ---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit87.h"
    // ---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm87 *Form87;
     
    // ---------------------------------------------------------------------------
    __fastcall TForm87::TForm87(TComponent* Owner) : TForm(Owner),
    MouseBtnPressed(false), CarteNr(0), PWight(0) {
     
    }
    // ---------------------------------------------------------------------------
     
    void __fastcall TForm87::EMouseUp(TObject *Sender, TMouseButton Button,
    	TShiftState Shift, int X, int Y) {
    	TPanel* LePanel = dynamic_cast<TPanel*>(Sender);
    	MouseBtnPressed = false;
    	SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
    }
    // ---------------------------------------------------------------------------
     
    void __fastcall TForm87::EMouseDown(TObject *Sender, TMouseButton Button,
    	TShiftState Shift, int X, int Y) {
    	TPanel* LePanel = dynamic_cast<TPanel*>(Sender);
    	MouseBtnPressed = true;
    	SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
    }
    // ---------------------------------------------------------------------------
     
    void __fastcall TForm87::EMouseMove(TObject *Sender, TShiftState Shift, int X,
    	int Y)
     
    {
    	TPanel* LePanel = dynamic_cast<TPanel*>(Sender);
    	if (LePanel && MouseBtnPressed) {
    		LePanel->Left += X;
    		LePanel->Top += Y;
    		SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
    	}
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TForm87::SendToStatusPanel(int x, int y, int Elem) {
    	StatusBar1->Panels->operator[](1)->Text = x;
    	StatusBar1->Panels->operator[](3)->Text = y;
    	StatusBar1->Panels->operator[](5)->Text = Elem;
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TForm87::Button1Click(TObject *Sender) {
    	TPanel* UnPanel = new TPanel(this);
    	const Larg = 50;
    	const Space = 5;
    	UnPanel->Parent = this;
    	UnPanel->Width = Larg;
    	++CarteNr;
    	UnPanel->Top = 0;
    	UnPanel->Left = PWight;
    	PWight += Larg + Space;
    	UnPanel->Tag = CarteNr;
    	UnPanel->Caption = "Carte " + IntToStr(CarteNr);
    	UnPanel->OnMouseMove = EMouseMove;
    	UnPanel->OnMouseUp = EMouseUp;
    	UnPanel->OnMouseDown = EMouseDown;
    	UnPanel->Visible = true;
    	SendToStatusPanel(UnPanel->Left, UnPanel->Top, UnPanel->Tag);
    }
    // ---------------------------------------------------------------------------
    bien cordialement
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  7. #7
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 132
    Par défaut
    Merci DjmSoftware.

    Je vais étudier ton code.

    Bonnes fêtes.

    Bien cordialement

  8. #8
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par défaut
    Salut
    ci-joint une variante du code précédent avec intégration d'un Bitmap dans le Panel simulant
    une carte
    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
     
    // ---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit87.h"
    // ---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm87 *Form87;
     
    // ---------------------------------------------------------------------------
    __fastcall TForm87::TForm87(TComponent* Owner) : TForm(Owner),
    MouseBtnPressed(false), CarteNr(0), PWight(0) {
     
    }
    // ---------------------------------------------------------------------------
     
    void __fastcall TForm87::EMouseUp(TObject *Sender, TMouseButton Button,
    	TShiftState Shift, int X, int Y) {
    	 TImage* moninage= dynamic_cast<TImage*>(Sender);// récupération de l'image séléctionnée
            TPanel* LePanel= dynamic_cast <TPanel*>(moninage->Parent);// récupération du panel contenant l'image
    	MouseBtnPressed = false;
    	SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
    }
    // ---------------------------------------------------------------------------
     
    void __fastcall TForm87::EMouseDown(TObject *Sender, TMouseButton Button,
    	TShiftState Shift, int X, int Y) {
    	  TImage* moninage= dynamic_cast<TImage*>(Sender);// récupération de l'image séléctionnée
       TPanel* LePanel= dynamic_cast <TPanel*>(moninage->Parent);// récupération du panel contenant l'image
    	MouseBtnPressed = true;
    	SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
    }
    // ---------------------------------------------------------------------------
     
    void __fastcall TForm87::EMouseMove(TObject *Sender, TShiftState Shift, int X,
    	int Y)
     
    {
       TImage* moninage= dynamic_cast<TImage*>(Sender);// récupération de l'image séléctionnée
       TPanel* LePanel= dynamic_cast <TPanel*>(moninage->Parent);// récupération du panel contenant l'image
     
    	if (LePanel && MouseBtnPressed) {
    		LePanel->Left += X;
    		LePanel->Top += Y;
    		SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
    	}
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TForm87::SendToStatusPanel(int x, int y, int Elem) {
    	StatusBar1->Panels->operator[](1)->Text = x;
    	StatusBar1->Panels->operator[](3)->Text = y;
    	StatusBar1->Panels->operator[](5)->Text = Elem;
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TForm87::Button2Click(TObject *Sender) {
    	TPanel* UnPanel = new TPanel(this);
    	const Larg = 50;
    	const Space = 5;
    	UnPanel->Parent = this;
    	UnPanel->Width = Larg;
    	++CarteNr;
    	UnPanel->Top = 0;
    	UnPanel->Left = PWight;
    	PWight += Larg + Space;
    	UnPanel->Tag = CarteNr;
    	TImage *Image1= new TImage(UnPanel);
    	Image1->Parent=UnPanel;
    	Image1->Tag= CarteNr;
    	Image1->Width=Larg;
    	Image1->Height=UnPanel->Height;
    	Image1->Picture->LoadFromFile("C:\\Windows\\System32\\SecurityAndMaintenance_Alert.png");
    	Image1->Stretch=true;
    	Image1->Visible=true;
    	//UnPanel->Caption = "Carte " + IntToStr(CarteNr);
    	Image1->Transparent=true;
    	Image1->OnMouseMove = EMouseMove;
    	Image1->OnMouseUp = EMouseUp;
    	Image1->OnMouseDown = EMouseDown;
    	SendToStatusPanel(Image1->Left, Image1->Top, Image1->Tag);
    }
    // ---------------------------------------------------------------------------
     
     
    void __fastcall TForm87::FormDestroy(TObject *Sender)
    {
    	 //
    }
    //---------------------------------------------------------------------------
    il est donc parfaitement inutile de stocker tes cartes dans un container ou un tableau
    La Form (Tapis) contient les Container Image (Tpanel)
    le destructeur de la form se charge automatiquement de la destruction de tous les objets contenus
    en ce qui concerne les images tu peux les stocker dans une TImageList ce qui nécessite quelques modifications mineures du code


    Ce code est un code pour la VCL tu dois l'adapter pour l'utilisation avec la FMX

    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  9. #9
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 132
    Par défaut
    Merci djmsoftware pour ton aide.

    Je vais essayer avec la VCL pour ensuite passer ce code en Firemonkey

    Bien cordialement

  10. #10
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 132
    Par défaut
    Bonsoir DjmSoftware

    Ci-dessous mon code FireMonkey qui permet d'empiler 104 cartes de manière aléatoire et de les déplacer sur l'écran.

    Cordialement

    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
     
    //  en H
    //---------------------------------------------------------------------------
     
    #ifndef Unit2H
    #define Unit2H
    //---------------------------------------------------------------------------
    #include <System.Classes.hpp>
    #include <FMX.Controls.hpp>
    #include <FMX.Forms.hpp>
    #include <FMX.Controls.Presentation.hpp>
    #include <FMX.Layouts.hpp>
    #include <FMX.Objects.hpp>
    #include <FMX.StdCtrls.hpp>
    #include <FMX.Types.hpp>
    #include <FMX.ImgList.hpp>
    #include <System.ImageList.hpp>
    //---------------------------------------------------------------------------
    class TForm2 : public TForm
    {
    __published:	// Composants gérés par l'EDI
    	TButton *Button1;
    	TImageList *ImageList1;
    	TGlyph *Glyph1;
    	void __fastcall Button1Click(TObject *Sender);
    	void __fastcall FormCreate(TObject *Sender);
     
     
    private:	// Déclarations utilisateur
       void __fastcall EMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y);
       void __fastcall EMouseMove(TObject *Sender, TShiftState Shift, float X,
    		  float Y);
       void __fastcall EMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y);
    	bool MouseBtnPressed;
        int XPos, YPos;  // pour déplacer les cartez
     
    public:		// Déclarations utilisateur
    	__fastcall TForm2(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm2 *Form2;
    //---------------------------------------------------------------------------
    #endif
     
    // en CPP
     
    //---------------------------------------------------------------------------
     
    #include <fmx.h>
    #pragma hdrstop
     
    #include "Unit2.h"
    #include <iostream>
    #include <string>
    #include <cstdlib>//Bibliothèques pour le random
    #include <ctime>
    #include <cstdio>
     
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.fmx"
    TForm2 *Form2;
     
    using namespace std;
     
     //******** fonctions pour les nombres aléatoires
     int random(const int MIN, const int MAX)
    {
    		int random;
    		return random = (rand() %  100+4);
    }
     
    int randomNoDouble(int min, int max, long *tableau, long sizeTableau, int i)
    {
    		bool ok;
     
    		do
    		{
    				tableau[i] = random(104);
    				ok = false;
    				if(i>0)
    				{
    						for(int j=0; j<sizeTableau && tableau[j] != -1;j++)
    						{
    							if(i != j && tableau[i] == tableau[j])
    								{
     
    										ok = true;                                }
    						}
    				}
    		}while(ok);
     
    		return tableau[i];
    }
    // ---------- fin des fonctions nombres aléatoires
     
     
     
    //---------------------------------------------------------------------------
    __fastcall TForm2::TForm2(TComponent* Owner)
    	: TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm2::EMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y)
    {
      TImage* moninage= dynamic_cast<TImage*>(Sender);// récupération de l'image séléctionnée
       TPanel* LePanel= dynamic_cast <TPanel*>(moninage->Parent);// récupération du panel contenant l'image
    	MouseBtnPressed = true;
        XPos = X;
    	YPos = Y;
        LePanel->BringToFront();
    }
     
    void __fastcall TForm2::EMouseMove(TObject *Sender, TShiftState Shift, float X,
    		  float Y)
    {
      TImage* moninage= dynamic_cast<TImage*>(Sender);// récupération de l'image séléctionnée
       TPanel* LePanel= dynamic_cast <TPanel*>(moninage->Parent);// récupération du panel contenant l'image
     
    	if (LePanel && MouseBtnPressed) {
    		LePanel->Position->X += X-XPos;
    		LePanel->Position->Y += Y-YPos;
    		}
    }
     
    void __fastcall TForm2::EMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
    		  float X, float Y)
    {
     TImage* moninage= dynamic_cast<TImage*>(Sender);// récupération de l'image séléctionnée
            TPanel* LePanel= dynamic_cast <TPanel*>(moninage->Parent);// récupération du panel contenant l'image
    	MouseBtnPressed = false;
    }
     
    void __fastcall TForm2::Button1Click(TObject *Sender)
    {
       srand(time(NULL));       // génère les nombre aléatoires
    		long size = 104;
    		long *tab = NULL;
    		int min = 0, max = 104;
     
    		tab = new long[size];
    		for (int i=0;i<104;i++)
    		{ tab[i] = -1; }
     
    		int j=0;
     
    // création et empligaes des 104 cartes de manière aléatoire
       // à l'aide d'ImageList et de Glyph  propriété Images de Glyph sur ImageList
    for (int i = 0; i < 104; i++)
       {
    	 j=randomNoDouble(min,max,tab,size,i);  // appelle la fonction qui caucule les nombres aléatoires
       TPanel* UnPanel = new TPanel(this);
    	UnPanel->Parent = this;
    	UnPanel->Height = Glyph1->Height;
    	UnPanel->Width = Glyph1->Width;
    	UnPanel->Position->X = 20;
    	UnPanel->Position->Y = 20;
    	UnPanel->Tag = j;
    	TImage *Image1= new TImage(UnPanel);
    	Image1->Parent=UnPanel;
    	Image1->Tag= j;
    	Image1->Height = Glyph1->Height;
    	Image1->Width = Glyph1->Width;
    	Glyph1->ImageIndex = j;
    	Image1->Bitmap->Assign(Glyph1->MakeScreenshot());
    	Image1->OnMouseMove = EMouseMove;
    	Image1->OnMouseUp = EMouseUp;
    	Image1->OnMouseDown = EMouseDown;
    	}
      delete[] tab;
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm2::FormCreate(TObject *Sender)
    {
    Glyph1->Height = 180;
    Glyph1->Width = 130;
    Glyph1->Visible = false;    // AutoHide de Glyph1 à false
    }
    //---------------------------------------------------------------------------

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Récupérer les coordonnées de plusieurs DIV dans une boucle PHP
    Par renaud26 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 05/11/2009, 10h23
  2. [PHP 5.2] Implementer plusieurs fichiers dans une boucle
    Par Mugette dans le forum Langage
    Réponses: 5
    Dernier message: 17/08/2009, 18h44
  3. afficher plusieurs composants dans une seule page
    Par groupe dans le forum GWT et Vaadin
    Réponses: 6
    Dernier message: 07/05/2008, 11h44
  4. declarer plusieurs JcheckBox dans une boucle
    Par 01211983 dans le forum Interfaces Graphiques en Java
    Réponses: 4
    Dernier message: 21/02/2008, 01h47
  5. Plusieurs composant dans une Jframe
    Par toitoine01 dans le forum Agents de placement/Fenêtres
    Réponses: 4
    Dernier message: 31/03/2006, 15h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo