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

Delphi Discussion :

Listage de contrôles avec un TTabsheet


Sujet :

Delphi

  1. #1
    Membre régulier

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    536
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 536
    Points : 121
    Points
    121
    Par défaut Listage de contrôles avec un TTabsheet
    Bonjour à tous

    Les boutons (TBitbtn) que je veux lister sont sur des GroupBox. C'est là le problème.

    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
     
    Procedure Desactiver_Ts_Boutons_Sur_TabSheet_Svgrd;
    Var
      i : integer;
     
    begin
     
      Form1.TabSheet_Svgrd.PageControl.ActivePage := Form1.TabSheet_Svgrd;
     
      for i := 0 to Form1.TabSheet_Svgrd.ControlCount -1 do
        begin
          if Form1.TabSheet_Svgrd.Controls[i] is TBitBtn then
            begin
              Form1.TabSheet_Svgrd.Controls[i].Enabled := False;  // l'exécution ne passe jamais là
            end;
        end;
    end;
    Je n'atteins pas les boutons.

    Avec la propriété TControl.Name
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Form1.Controls[i].Name
    je m'aperçois que ma boucle ne liste que les GroupBox, pas les boutons.

    Y a-t-il un moyen un peu moins bourrin que lister manuellement ces boutons ds un tableau de TControl ?

    Merci

  2. #2
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 042
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 042
    Points : 40 952
    Points
    40 952
    Billets dans le blog
    62
    Par défaut
    Bonjour,

    AMHA il manque une boucle, un essai non testé

    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
     
    Procedure Desactiver_Ts_Boutons_Sur_TabSheet_Svgrd;
    Var
      i,b : integer;
      aParent : TControl;  // j'ai juste un doute sur le type d'objet TWinControl ? TObject ? 
     
    begin
     
      Form1.TabSheet_Svgrd.PageControl.ActivePage := Form1.TabSheet_Svgrd;
     
      for i := 0 to Form1.TabSheet_Svgrd.ControlCount -1 do
        begin
          if Form1.TabSheet_Svgrd.Controls[i] is TGroupBox then
            begin
              AParent:=Form1.TabSheet_Svgrd.Controls[i];
              For j:=0 to AParent.ControlCount - 1 do
               begin
                 if Aparent.Contols[j] is TButton then  
                    AParent.Controls[i].Enabled := False; 
               end;
            end;
        end;
    end;
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  3. #3
    Membre régulier

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    536
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 536
    Points : 121
    Points
    121
    Par défaut
    Bonjour

    Repris la procédure comme ceci :
    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
     
    Procedure Desactiver_Ts_Boutons_Sur_TabSheet_Svgrd_Bis;
    Var
      i, j : integer;
    //  aParent : TObject;  
     aParent : TWinControl; 
    // aParent : TControl;  
    //  aParent : TGroupBox; 
     
    begin
     
      Form1.TabSheet_Svgrd.PageControl.ActivePage := Form1.TabSheet_Svgrd;
     
      for i := 0 to Form1.TabSheet_Svgrd.ControlCount -1 do
        begin
          if Form1.TabSheet_Svgrd.Controls[i] is TGroupBox then
            begin
              AParent := Form1.TabSheet_Svgrd.Controls[i];
     
              For j := 0 to AParent.ControlCount - 1 do
               begin
                 if Aparent.Controls[j] is TButton then AParent.Controls[i].Enabled := False;
               end;
            end;
        end;
     
    end;
    Effectivement. Il manquait une boucle, pour atteindre les boutons sur le GroupBox. Mais je n'arrivais pas à atteindre les boutons à travers le GroupBox. La déclaration de TGroupBox est ici.

    Si aParent est déclaré TWinControl, j'ai ce msg d'erreur, mais c'est là que j'ai le moins d'erreurs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    TWinControl : [dcc32 Erreur] Affichages.pas(134): E2010 Types incompatibles : 'TWinControl' et 'TControl'
    S'il est TControl, j'ai ces messages-là :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    [dcc32 Erreur] Affichages.pas(136): E2003 Identificateur non déclaré : 'ControlCount'
    [dcc32 Erreur] Affichages.pas(138): E2003 Identificateur non déclaré : 'Controls'
    [dcc32 Erreur] Affichages.pas(138): E2015 Opérateur non applicable à ce type d'opérande
    [dcc32 Erreur] Affichages.pas(138): E2003 Identificateur non déclaré : 'Controls'
    Si aParent est TGroupBox, j'ai ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Avec TGroupBox : [dcc32 Erreur] Affichages.pas(134): E2010 Types incompatibles : 'TGroupBox' et 'TControl'
    C'est pourtant bien d'un TWinControl qu'il s'agit :
    Nom : 22b8300a9379f19b57241906333f44590cf294d9.png
Affichages : 163
Taille : 31,5 Ko


  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 042
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 042
    Points : 40 952
    Points
    40 952
    Billets dans le blog
    62
    Par défaut
    il faut donc déclarer aParent comme un TControl mais peut être forcer l'assignation
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    AParent := TControl(Form1.TabSheet_Svgrd.Controls[i]);
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  5. #5
    Membre régulier

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    536
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 536
    Points : 121
    Points
    121
    Par défaut
    J'ai à peu près résolu.

    Alors, en suivant ta méthode :



    Du coup, j'ai fait un brouillon :
    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
     
    Procedure Desactiver_4;
    Var
      i : integer;
      Tab_GroupBox : array of TWinControl;
      Nb_GroupBox : integer;
      Idx_Tab : integer;
     
    begin
      Form1.TabSheet_Svgrd.PageControl.ActivePage := Form1.TabSheet_Svgrd;
      Nb_GroupBox := -1;
      Idx_Tab := 0;
      SetLength(Tab_GroupBox, 10); // On n'en aura jamais 10
     
      for i := 0 to Form1.TabSheet_Svgrd.ControlCount -1 do
        begin
          if Form1.TabSheet_Svgrd.Controls[i] is TGroupBox then
            begin
              INC(Nb_GroupBox);
              Tab_GroupBox[Idx_Tab] := TGroupBox(Form1.TabSheet_Svgrd.Controls[i]);
              INC(Idx_Tab);
            end;
        end;
     
      Aff_Ds_StatusBar('Nb GroupBox : ' + IntToStr(Nb_GroupBox), @Form1.StatusBar);
     
      for i := 0 to Nb_GroupBox do
        begin
          if Tab_GroupBox[i].Controls[i] is TBitBtn then Tab_GroupBox[i].Enabled := False;
        end;
     
      SetLength(Tab_GroupBox, 0);
     
    end;
    Là, ils sont bien "Disabled"... mais ils n'apparaissent pas en grisé. Pas contre, il sont inactifs. Et même s'ils ont un curseur crHandPoint, une fois désactivés, ils ne l'ont effectivement plus.

    Pour l'instruction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Tab_GroupBox[i] := TGroupBox(Form1.TabSheet_Svgrd.Controls[i]);
    j'ai dû forcer le type à TGoupBox. Un transtypage indispensable pour le compilo qui me refusait toute autre syntaxe.

    Je corrigerai l'allocation du Tab_GroupBox. J'ai vérifié : un SetFocus sur l'un des boutons provoque effectivement une erreur. Logique.

Discussions similaires

  1. [RegEx] Contrôle avec expression régulière
    Par lodan dans le forum Langage
    Réponses: 8
    Dernier message: 23/10/2006, 19h32
  2. Accéder à un contrôle avec son numéro
    Par nattyman dans le forum Access
    Réponses: 2
    Dernier message: 23/09/2006, 06h47
  3. [C#] Création d'un contrôle avec collection intégrée
    Par nerix dans le forum Windows Forms
    Réponses: 2
    Dernier message: 28/06/2006, 10h07
  4. [PostGreSQL] contrôle avec une requête
    Par flo78 dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 30/01/2006, 10h52
  5. Réponses: 3
    Dernier message: 15/11/2005, 18h50

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