Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Memory allocation problem with property store Collapse All
Subject Author Date
Andreas Werner Oct 25, 2006 - 9:50 AM

Hallo,

first of all thank you Suhai Gyorgy for your help yesterday with the CExtControlBar. Now I have my list and my property grid displayed correctly in the window of the control bar.

I have problems with the memory allocation of CExtpropertyStore. I have a class that derives from CExtResizableDialog. This dialog contains my property grid with its property store. My first approach was the following. I declared the property store and the items as members of the dialog.

CDialog2.h:
CExtPropertyStore m_PS;
CExtPropertyCategory m_Category
Etc …

In the OnInitDialog Method of the CDialog2 class I add the items to the property store.

m_PS.NameSet(_T("PS Name"));    
m_Category.NameSet (_T("Category Name") );
m_Category.DescriptionSet( _T("Category Description") );
VERIFY( m_PS.ItemInsert( &m_Category ) );
Etc …

In the destructor of the CDialog2 class I invoke:

m_PS.ItemRemove();

When I stop the application I get an access violatioan:
HEAP[FullScreenState-ynd.exe]: Invalid Address specified to RtlValidateHeap( 00330000, 00338EDC )
A call of the ItemRemove methode on the property store



My second approach was to use only pointer variables and to call the Delete method of property store in the destructor of the CDialog2 class.

CDialog2.h:
CExtPropertyStore m_pPS;
CExtPropertyCategory m_pCategory
Etc …

In the OnInitDialog Method of the CDialog2 class I instantiate the property store and the items and add the items to the property store.

m_pPS = new CExtPropertyStore ();
m_pPS->NameSet(_T("PS Name"));    
CExtPropertyCategory m_pCategory = new CExtPropertyCategory ();
m_pCategory->NameSet (_T("Category Name") );
m_pCategory->DescriptionSet( _T("Category Description") );
VERIFY( m_PS->ItemInsert( m_pCategory ) );
Etc …

In the destructor of the CDialog2 class I invoke: m_pPS->Delete();

Now the application terminates without memory access violation.



By the way, I still use the FullScreenState example as template. The instance of the CDialog2 I use is a member of the CMainFrame class of that example. I connect the dialog to the control bar in the OnCreate methode of the CMainFrame class.



My question is:
How can I use a property store as member field?
How can free the memory correctly if I use a property store object as a member field?



With best regards Andreas

Technical Support Oct 26, 2006 - 5:34 AM

Please use property categories and values and dynamically allocated with C++ new operator objects only. The CExtPropertyCategory and CExtPropertyValue objects will be deleted automatically with C++ delete operator when the parent objects are deleted.

The CExtPropertyGridCtrl window only uses the assigned CExtPropertyStore object and never deletes it. So if you are using the property store as CExtPropertyStore-based member of some class, then you should not delete anything.