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

Composants VCL Delphi Discussion :

Composant non visuel: débordement de pile


Sujet :

Composants VCL Delphi

  1. #1
    Expert éminent
    Avatar de qi130
    Homme Profil pro
    Expert Processus IT
    Inscrit en
    Mars 2003
    Messages
    3 901
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France

    Informations professionnelles :
    Activité : Expert Processus IT
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 3 901
    Points : 6 026
    Points
    6 026
    Par défaut Composant non visuel: débordement de pile
    Bonjour,

    Je cherche à réaliser un composant non visuel qui fonctionnerait un peu comme un TRadioGroup avec 4 états exclusifs les uns des autres.

    J'ai pondu ça
    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
    unit decision;
     
    interface
     
    uses Windows, Messages, SysUtils, Classes;
     
    type TEtat = (eCreation,eModification,eVisualisation,eSuppression);
     
    const EtatStr: array[TEtat] of string = (
          'Création','Modification','Visualisation','Suppression');
     
    type TGestionGroupe = class(TComponent)
     
         private
            Creation,
            Modification,
            Visualisation,
            Suppression: Boolean;
            function FLibelle:string;
            procedure SetLibelle(const valeur:string);
            function FItemIndex:Integer;
            procedure SetItemIndex(indice:Integer);
            function GetEtat: TEtat;
            procedure SetEtat(const valeur:TEtat);
         protected
     
         public
            constructor Create(AOwner: TComponent); override;
            destructor Destroy; override;
            procedure SetToCreation;
            procedure SetToModification;
            procedure SetToVisualisation;
            procedure SetToSuppression;
            property ItemIndex:Integer  read FItemIndex write SetItemIndex default 0;
            property Libelle:string read FLibelle write SetLibelle;
         published
            property Etat:TEtat read GetEtat write SetEtat ;
         end;
     
    procedure Register;
     
    implementation
     
    constructor TGestionGroupe.Create(AOwner: TComponent);
    begin
      inherited;
      ItemIndex:=0;
    //  Etat:=eCreation;
      Libelle:='Création'; //EtatStr[Etat];
    end;
     
    destructor TGestionGroupe.Destroy;
    begin
      inherited;
    end;
     
    function TGestionGroupe.FLibelle:string;
    begin
    //     Result:=EtatStr[Etat];
    end;  
    procedure TGestionGroupe.SetLibelle(const valeur:string);
    begin
    //     Libelle:=valeur;
    end;
    function TGestionGroupe.FItemIndex:Integer;
    begin
    //     Result:=ItemIndex;
    end;
    procedure TGestionGroupe.SetItemIndex(indice:Integer);
    begin
         ItemIndex:=indice;
    //     SetEtat(TEtat(indice));
    end;
    function TGestionGroupe.GetEtat: TEtat;
    begin
    //     Result:=TEtat(ItemIndex);
    end;
    procedure TGestionGroupe.SetEtat(const valeur:TEtat);
    begin
    //     Etat:=valeur;
    //     Creation:=False ;
    //     Modification:=False ;
    //     Visualisation:=False ;
    //     Suppression:=False ;
    //     SetLibelle(EtatStr[valeur]);
    //     if valeur=eCreation then Creation:=true
    //        else if valeur=eModification then Modification:=true
    //           else if valeur=eVisualisation then Visualisation:=true
    //              else Suppression:=true ;
     
    end;
    procedure TGestionGroupe.SetToCreation;
    begin
         SetItemIndex(0);
    end;
    procedure TGestionGroupe.SetToModification;
    begin
         SetItemIndex(1);
    end;
    procedure TGestionGroupe.SetToVisualisation;
    begin
         SetItemIndex(2);
    end;
    procedure TGestionGroupe.SetToSuppression;
    begin
         SetItemIndex(3);
    end;
     
    procedure Register;
    begin
      RegisterComponents('Exemples', [TGestionGroupe]);
    end;
     
    end.
    Beaucoup de code en commentaire car quand je dépose ce compo sur 1 fiche, j'ai "débordement de pile. Sauvegarder et relancer Delphi", et je cherche d'où vient le problème...

    Je concède que la création de compo n'est pas ma tasse de thé et toute aide est la bienvenue.
    "Il n'y a pas de bonnes réponses à une mauvaise question." (M. Godet)
    -----------------------
    Pensez à cloturer votre sujet - Aucune réponse aux sollicitations techniques par MP
    Usus magister est optimus

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Février 2008
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 141
    Points : 142
    Points
    142
    Par défaut
    Attention, quand tyu crées une propriété, dans le cas qui nous intéresse Etat, faire "Etat := toto" appelle la fonction SetEtat.

    Du coup ta fonction SetEtat:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    procedure TGestionGroupe.SetEtat(const valeur:TEtat);
    begin
         Etat:=valeur;
    end;
    s'appelle récursivement sans arrêt.

    Supprime cette première ligne.

    Ensuite, pourquoi tu préfères avoir 4 booléens plutôt qu'une variable de type TEtat?
    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
     
    type TGestionGroupe = class(TComponent)
         private
            FEtat : TEtat;
            ...
     
        ...
    end;
     
      ...
     
    procedure TGestionGroupe.SetEtat(const valeur:TEtat);
    begin
         FEtat:=valeur;
    //et la suite...
    end;
    *LeGEC*

  3. #3
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Salut

    Dans la partie private:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
        private
            // ...
            function FLibelle:string;
            // ...
            function FItemIndex:Integer;
            // ...
    Koitès ces fonctions ?

    Cela devrait être plutôt des champs de la classe, non ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
        FLibelle: string;
        FItemIndex: Integer;
    @+

  4. #4
    Membre chevronné

    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2002
    Messages
    1 288
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2002
    Messages : 1 288
    Points : 1 936
    Points
    1 936
    Par défaut
    Le problème est que tu appelles SetItemIndex en boucle.

    ItemIndex := 0 déclenche SetItemIndex et dans SetItemIndex tu réaffectes ItemIndex.

    Je vois pour récrire une partie
    Delphi 7/XE2/XE3
    C#
    Oracle 9i à 12c
    SQL Server 2008 à 2014

  5. #5
    Membre chevronné

    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2002
    Messages
    1 288
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2002
    Messages : 1 288
    Points : 1 936
    Points
    1 936
    Par défaut
    Je ferais plus de cette façon, tout tourne autour de la valeur de FEtat.
    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
     
    unit GestionGroup;
     
    interface
     
    uses Windows, Messages, SysUtils, Classes;
     
    type TEtat = (eCreation,eModification,eVisualisation,eSuppression);
     
    const EtatStr: array[TEtat] of string = (
          'Création','Modification','Visualisation','Suppression');
     
    type TGestionGroupe = class(TComponent)
     
         private
            FEtat:TEtat;
            procedure SetEtat(const valeur:TEtat);
            function GetItemIndex: Integer;
            function GetLibelle: string;
         protected
     
         public
            constructor Create(AOwner: TComponent); override;
            procedure SetToCreation;
            procedure SetToModification;
            procedure SetToVisualisation;
            procedure SetToSuppression;
            function Creation : Boolean;
            function Modification : Boolean;
            function Visualisation : Boolean;
            function Suppression : Boolean;
            property ItemIndex:Integer  read GetItemIndex;
            property Libelle:string read GetLibelle;
         published
            property Etat:TEtat  read FEtat write SetEtat;
         end;
     
    procedure Register;
     
    implementation
     
    constructor TGestionGroupe.Create(AOwner: TComponent);
    begin
      inherited;
      SetToCreation;
    end;
     
    procedure TGestionGroupe.SetEtat(const valeur:TEtat);
    begin
       FEtat:=valeur;
    end;
    procedure TGestionGroupe.SetToCreation;
    begin
         SetEtat(eCreation);
    end;
    procedure TGestionGroupe.SetToModification;
    begin
         SetEtat(eModification);
    end;
    procedure TGestionGroupe.SetToVisualisation;
    begin
         SetEtat(eVisualisation);
    end;
    procedure TGestionGroupe.SetToSuppression;
    begin
         SetEtat(eSuppression);
    end;
     
    procedure Register;
    begin
      RegisterComponents('Exemples', [TGestionGroupe]);
    end;
     
    function TGestionGroupe.Creation: Boolean;
    begin
      Result := FEtat = eCreation;
    end;
     
    function TGestionGroupe.GetLibelle: string;
    begin
      Result := EtatStr[FEtat];
    end;
     
    function TGestionGroupe.Modification: Boolean;
    begin
      Result := FEtat = eModification;
    end;
     
    function TGestionGroupe.Suppression: Boolean;
    begin
      Result := FEtat = eSuppression;
    end;
     
    function TGestionGroupe.Visualisation: Boolean;
    begin
      Result := FEtat = eVisualisation;
    end;
     
    function TGestionGroupe.GetItemIndex: Integer;
    begin
      Result := Ord(FEtat);
    end;
     
     
    end.
    Delphi 7/XE2/XE3
    C#
    Oracle 9i à 12c
    SQL Server 2008 à 2014

  6. #6
    Expert éminent
    Avatar de qi130
    Homme Profil pro
    Expert Processus IT
    Inscrit en
    Mars 2003
    Messages
    3 901
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France

    Informations professionnelles :
    Activité : Expert Processus IT
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 3 901
    Points : 6 026
    Points
    6 026
    Par défaut
    Je vois que j'ai pondu beaucoup de c........

    Je regarde tout ça et comme c'est beau un truc qui fonctionne !

    Dernier point : comment obtenir l'enrichissement de la clause use lors du dépot du composant ?
    EDIT: en fait, ça se produit à la compil....

    Donc c ok à tous
    "Il n'y a pas de bonnes réponses à une mauvaise question." (M. Godet)
    -----------------------
    Pensez à cloturer votre sujet - Aucune réponse aux sollicitations techniques par MP
    Usus magister est optimus

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

Discussions similaires

  1. [Prism] composant non visuel
    Par rvzip64 dans le forum Delphi .NET
    Réponses: 3
    Dernier message: 13/02/2009, 12h05
  2. composant non visuel
    Par rvzip64 dans le forum Windows Forms
    Réponses: 3
    Dernier message: 27/01/2009, 21h03
  3. Réponses: 2
    Dernier message: 19/09/2008, 18h15
  4. Creer un composant non visuel(Timer) dans une DLL
    Par hugobob dans le forum Composants VCL
    Réponses: 1
    Dernier message: 06/06/2006, 16h20
  5. Destructeur pour un composant non visuel
    Par sfpx dans le forum Composants VCL
    Réponses: 4
    Dernier message: 27/08/2005, 02h14

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