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

MFC Discussion :

Problemme de serialisation d'une collection


Sujet :

MFC

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 16
    Par défaut Problemme de serialisation d'une collection
    Bonjour a tous;

    Comme dit dans le titre je n'arrives pas a serialiser ma collection ...

    Si je la serialise directemment au moment de la retrouver le programme plante avec une belle erreur de segmentation ...

    et Si j'essayes de serialiser item par item je ne recupere aucune valeur ...

    La fonction d'archive et de recuperation

    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
     
    int archivacteur(){
     
     
       if( !f.Open( "lesacteurs.txt", CFile::modeCreate | CFile::typeBinary | CFile::modeWrite ) ) {
    	   cout << "Impossible d'ouvrir le fichier lesacteurs.txt" << "\n";
           system("pause");
    	   return EXIT_FAILURE;
       }
       CArchive ar1( &f, CArchive::store);
       listeact.Serialize(ar1);
       ar1.Close();
       f.Close();
       return EXIT_SUCCESS;
     
    }
     
    int seretrouve(){
     
       if( !f.Open( "lesacteurs.txt", CFile::modeRead ) ) {
    	   cout << "Impossible d'ouvrir le fichier lesacteurs.txt" << "\n";
           system("pause");
    	   return EXIT_FAILURE;
       }
       CArchive ar1( &f, CArchive::load);
       listeact.RemoveAll();
       listeact.Serialize(ar1);
       ar1.Close();
       f.Close();
       return EXIT_SUCCESS;
    }

    La definition de ma collection et de mes objets

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    acteur Monacteur, Monacteur2;
    CFile f;
    typedef CArray <acteur,acteur&> Mesacteurs;
     
     
    Mesacteurs listeact;
    Merci d'avance ...
    @bientôt

    PS: Je penses avoir suivit la méthode de la FAQ ...

  2. #2
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par défaut
    salut,
    rajoute le mode CFile::typeBinary sur la lecture...

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 16
    Par défaut
    Non ca ne marche toujours pas ....

    Quand je veux afficher les objets de la collection elle plante ...

    code de l'affichage ( j'avai soublie de le mettre )

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    for (i=0;i<listeact.GetSize();i++){
            listeact.GetAt(i).afficher();
    	cout <<endl << endl;
    }

  4. #4
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par défaut
    heu c'est quoi qui plante ?
    la lecture de l'archive ,l'affichage ?

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 16
    Par défaut
    Bah apparemment la lecture de l'archive se passe bien .... Je recupere le bon nombre d'items en tout cas



    Ca plante quand j'essaye d'acceder à un des elements de la collection pour l'afficher ...

  6. #6
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par défaut
    tu peux indiquer l'erreur et la ligne de code en question ....?

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 16
    Par défaut
    ligne 65 :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    listeact.GetAt(i).afficher();
    et l'erreur :

    Unhandled exeption in PTI.exe: oxC0000005: Access violation

  8. #8
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par défaut
    ce n'est pas suffisant..., je suis sûr que tu peux rentrer dans le code et avoir plus de détail....

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 16
    Par défaut
    ok je vais essayer mais je garantit rien ^^

    rapport du debugg


    rapport avant la ligne posant problemme ...

    Loaded 'ntdll.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
    Loaded symbols for 'C:\WINDOWS\system32\MFC42D.DLL'
    Loaded symbols for 'C:\WINDOWS\system32\MSVCRTD.DLL'
    Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
    Loaded symbols for 'C:\WINDOWS\system32\MSVCP60D.DLL'
    Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
    Loaded 'C:\Program Files\Kaspersky Lab\Kaspersky Internet Security 6.0\adialhk.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\mfc42loc.dll', no matching symbolic information found.
    Warning: CFile::GetStatus() returns m_attribute without high-order flags.
    Loaded 'C:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\MSCTF.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\version.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\MSCTFIME.IME', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\ole32.dll', no matching symbolic information found.
    Loaded 'C:\Program Files\Microsoft Hardware\Mouse\Msh_zwf.dll', no matching symbolic information found.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe (MSVCRTD.DLL): 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.

    rapport au moment ou le debbugger passe sur la ligne ...

    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    ( ... la meme chose se repetant beaucoup de fois )
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe (NTDLL.DLL): 0xC00000FD: Stack Overflow.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    First-chance exception in PTI.exe: 0xC0000005: Access Violation.
    variable listeact ( ma collection ) apres la recup des données :

    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
     
    -	listeact	{CArray<acteur,acteur &>}
    -	CObject	{CObject}
    -	__vfptr	0x0041a4dc const CArray<class acteur,class acteur &>::`vftable'
    	[0]	0x0040704e CObject::GetRuntimeClass
    	[1]	0x00401145 CArray<class acteur,class acteur &>::`vector deleting destructor'(unsigned int)
    	[2]	0x00401082 CArray<class acteur,class acteur &>::Serialize(class CArchive &)
    	[3]	0x004010fa CArray<class acteur,class acteur &>::AssertValid(void)
    	[4]	0x004010b9 CArray<class acteur,class acteur &>::Dump(class CDumpContext &)
    -	m_pData	0x00421750
    -	Personne	{Personne}
    -	CObject	{CObject}
    -	__vfptr	0x0041a024 const acteur::`vftable'
    	[0]	0x0040103c acteur::GetRuntimeClass(void)
    	[1]	0x00401064 acteur::`scalar deleting destructor'(unsigned int)
    	[2]	0x00406fd0 CObject::Serialize
    	[3]	0x00406fca CObject::AssertValid
    	[4]	0x00406fc4 CObject::Dump
    -	classPersonne	{"Personne"}
    -	m_lpszClassName	0x0041a040 "Personne"
    		80 'P'
    	m_nObjectSize	20
    	m_wSchema	1
    	m_pfnCreateObject	0x0040112c Personne::CreateObject(void)
    	m_pfnGetBaseClass	0x00401177 Personne::_GetBaseClass(void)
    -	m_pNextClass	0x0041b5e0 struct CRuntimeClass acteur::classacteur
    -	m_lpszClassName	0x0041a01c "acteur"
    		97 'a'
    	m_nObjectSize	32
    	m_wSchema	1
    	m_pfnCreateObject	0x0040114f acteur::CreateObject(void)
    	m_pfnGetBaseClass	0x004010af acteur::_GetBaseClass(void)
    -	m_pNextClass	0x00000000 {???}
    	m_lpszClassName	CXX0030: Error: expression cannot be evaluated
    	m_nObjectSize	CXX0030: Error: expression cannot be evaluated
    	m_wSchema	CXX0030: Error: expression cannot be evaluated
    	m_pfnCreateObject	CXX0030: Error: expression cannot be evaluated
    	m_pfnGetBaseClass	CXX0030: Error: expression cannot be evaluated
    	m_pNextClass	CXX0030: Error: expression cannot be evaluated
    	C_ID	1
    -	C_prenom	{""}
    -	m_pchData	0x004214dc ""
    		16 ''
    -	C_nom	{""}
    -	m_pchData	0x0042152c ""
    		1 ''
    -	C_ville	{"Q"}
    -	m_pchData	0x0042140c "Q"
    		81 'Q'
    -	classacteur	{"acteur"}
    -	m_lpszClassName	0x0041a01c "acteur"
    		97 'a'
    	m_nObjectSize	32
    	m_wSchema	1
    	m_pfnCreateObject	0x0040114f acteur::CreateObject(void)
    	m_pfnGetBaseClass	0x004010af acteur::_GetBaseClass(void)
    -	m_pNextClass	0x00000000 {???}
    	m_lpszClassName	CXX0030: Error: expression cannot be evaluated
    	m_nObjectSize	CXX0030: Error: expression cannot be evaluated
    	m_wSchema	CXX0030: Error: expression cannot be evaluated
    	m_pfnCreateObject	CXX0030: Error: expression cannot be evaluated
    	m_pfnGetBaseClass	CXX0030: Error: expression cannot be evaluated
    	m_pNextClass	CXX0030: Error: expression cannot be evaluated
    	C_nbapparition	1
    	C_cachet	1.0000000000000
    	m_nSize	1
    	m_nMaxSize	1
    	m_nGrowBy	0
    Je mets l'archi de mes classes au cas où ..

    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
     
     
    class acteur  :public Personne {
    	DECLARE_SERIAL(acteur)
    private:
    	int C_nbapparition;
    	double C_cachet;
    public:
    	acteur();
    	acteur(const acteur &act){
    		C_ID=act.C_ID;
    		C_nom=act.C_nom;
    		C_prenom=act.C_prenom;
    		C_ville=act.C_ville;
    		C_cachet=act.C_cachet;
    		C_nbapparition=act.C_nbapparition;
     
    	}
    	int get_nbapparition();
    	double  get_cachet();
    	void set_nbapparition(int nbapp);
    	void set_cachet(double cachet);
    	void init_acteur(int ID, CString prenom, CString nom,CString ville,int nbapparition,double cachet);
    	void serialize(CArchive &ar);
        acteur& operator=( const acteur &act){
    		C_ID=act.C_ID;
    		C_nom=act.C_nom;
    		C_prenom=act.C_prenom;
    		C_ville=act.C_ville;
    		C_cachet=act.C_cachet;
    		C_nbapparition=act.C_nbapparition;
    		return *this;
    	}
    	void afficher(){
    		cout << "numero de l'acteur : "<< C_ID << endl; 
    		printf("Nom de l'acteur : %s\n",C_nom);
    		printf("Prenom de l'acteur %s\n",C_prenom);
    		cout <<"Cachet de l'acteur : "<< get_cachet() << endl;
    	}
    }
     
    class Personne :public CObject
    {
    DECLARE_SERIAL(Personne)
    public:
    	Personne();
    	int C_ID;
    	CString C_prenom;
    	CString C_nom;
    	CString C_ville;
     
    	int get_ID();
    	CString get_prenom();
    	CString get_nom();
    	CString get_ville();
    	void set_ID(int id);
    	void set_prenom(CString prenom);
    	void set_nom(CString nom);
    	void set_ville(CString ville);
    	void init(int ID, CString prenom, CString nom,CString ville);
    	void serialize(CArchive &ar);
    };

Discussions similaires

  1. Réponses: 2
    Dernier message: 27/04/2010, 15h58
  2. Serialisation d'objet contenant une collection
    Par Invité dans le forum Langage
    Réponses: 5
    Dernier message: 21/08/2006, 08h37
  3. [VB6] Sauvegarder une collection d'objets
    Par Sayagh dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 19/09/2003, 11h58
  4. Comment créér une collection sous Delphi
    Par PsyKroPack dans le forum Langage
    Réponses: 6
    Dernier message: 11/02/2003, 13h20
  5. [VB6] Modifier la clé d'un élément d'une collection
    Par Ricou13 dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 21/11/2002, 14h49

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