Bonjour,

j'ai un petit souci de conception et mon problème n'est pas forcemment complexe mais long à expliquer.C'est pourquoi j'ai découpé le problème en morceaux.

Introduction:
Mon objectif est d'afficher/modifier dans un controle graphique les differents champs de mes objets.
Pour cela j'utilise un controle MFC de type EPropCtrl avec une classe IPropertyHost definie de la manière suivante :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
class IPropertyHost
{
public:
    virtual void GetProperties( EPropList& PropList ) {}
};
 
// mon controle graphique (ressemble a un listBox)
class EPropCtrl
{
    public:
    SetPropPointer( IPropertyHost* pHost);
};

Pratiquement si j'ai une classe simple (class Simple)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
class Simple
{
protected:
    int iValue;
};
dont je veux afficher/modifier les propriétes je fais la chose suivante

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
 
class SimpleProp : public Simple,
                   public IPropertyHost
{
public:
    virtual void     GetProperties( EPropList& PropList )
    {
        PropList.AddPropInt(this,_T("iValue"),&iValue, false);
    }
 
 
 
    IPropertyHost*     GetPropPointer() { return this; }
protected:
    int iValue;
};
Ensuite j'appelle mon controle comme ca:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
EPropCtrl  objPropCtrl; // Objet graphique affichant des propriétes
SimpleProp simpleProp; //Objet SimpleProp
objPropCtrl.SetPropPointer( simpleProp.GetPropPointer() );
//JUSQU ICI TOUT VA BIEN ET CA FONCTIONNE

//----------------------------------------------------------------
// maintenant considerons les objets suivants B et A encapsulant
// l'acces a des structures imbriquees

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
 
typedef struct tagStructB
{
    int        iSizeB;
    char*    szTextB;
} StructB;
 
typedef struct tagStructA
{
    int        iSizeA;
    char*    szTextA;
    StructB sStructB;
} StructA;
 
 
class B
{
public:
    B(structB& refStructB) { m_refStructB = refStructB ;}
    int        GetSize() {return m_StructB.iSizeB;}
    char*    GetText() {return m_StructB.szTextB;}
 
protected:
    structB& m_refStructB;
};
 
 
class A
{
public:
    A();
    int        GetSize() {return m_StructA.iSizeA;}
    char*    GetText() {return m_StructA.szTextA;}
    B&        GetB() { return m_B; }
 
 
protected:
    structA m_StructA;
    B        m_B;
};
 
Use :
 
A m_a;
int iSizeA = m_A.GetSize(); // recupere la valeur du champ de ma structure A
m_A.GetB().GetSize();
Si je veux afficher les proprietes avec mon controle graphique et en prenant le modèle précédent

Je vais vouloir faire :

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
 
class BProp: public B,
             public IPropertyHost
{
    public:
        virtual void     GetProperties( EPropList& PropList ) { PropList.AddPropInt(this,_T("iSizeB"),&m_refStructB.iSizeB, false);
PropList.AddPropString(this,_T("szTextB"),&m_refStructB.szTextB, false);
 
        IPropertyHost*     GetPropPointer() { return this; }
};
 
class AProp: public A,
             public IPropertyHost
{
    public:
        virtual void     GetProperties( EPropList& PropList )
        {
 
PropList.AddPropInt(this,_T("iSizeA"),&m_StructA.iSizea, false);
PropList.AddPropString(this,_T("szTextA"),&m_StructA.szTextA, false);
 
///////////// PROBLEME /////////////////////
            m_B.GetProperties( PropList );
 
  //En effet je ne peux pas appeler GetProperties car appartient a Bprop et non pas a B
 
 
 
        }
 
 
        IPropertyHost*     GetPropPointer() { return this; }
};
 
 
 
EPropCtrl  objPropCtrl; // Objet graphique affichant des propriétes
AProp        objAProp; //Objet AProp
 
objPropCtrl.SetPropPointer( objAProp.GetPropPointer() );
/////////////////// PROBLEME : COmment architecture mon soft
Pour que je puisse afficher les propriétes de mon objet A ainsi que du B a l'interieur ????