Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Oct 15, 2018 3:57 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Returning Object pointers from Plugin
PostPosted: Mon Jan 09, 2006 8:42 am 
Offline

Joined: Fri Sep 30, 2005 8:47 am
Posts: 100
Hi,

After finding memory leaks from the XMLDocument class in RB:

http://www.realsoftware.com/feedback/viewreport.php?reportid=iknjcmhx
http://www.realsoftware.com/feedback/viewreport.php?reportid=rfgumccn

I have been forced to write my own XML Parser and XQL support. Now I have this working in C++ as XMLNode, XMLDocument (inherits XMLNode) and XMLNodeList (results from an XQL).

I have written a couple of class based plugins in the past and am familiar with the struct usage and the ClassData macros to retrieve the class etc. But now I am faced with an unique challenge.

XMLDocument or XMLNode have a function called GetChild(index) which is supposed to return an XMLNode.... How do I code for this ? Because, ClassData can convert a REALObject to a C object but what about the reverse when I want to massage a C Object into a REALObject reference and return the value to RB. Keeping in mind that the XMLNodes are created in C (using the new operator whilst doing a LoadXML) and I destroy them with the object is destroyed.

Similarly the XMLNode's XQL function creates a "new" XMLNodeList and this too needs to be returned to RB. But in this case I need to delete the "new" item.


Some snippets from my XML class.

class CXMLDocument : public CXMLNode
{
/* .... removed for clarity ... */
public :
bool LoadXML(CString xmlString);
};


class CXMLNode
{
/* .... removed for clarity ... */
public :
CString ToString();
CXMLNode* GetChild(int index);
CXMLNode* AddChild(CString setName);
CXMLNodeList* Xql(CString XPathQuery);
};


class CXMLNodeList
{
/* .... removed for clarity ... */
public :
int AddItem(CXMLNode* newItem);
CXMLNode* GetItem(int index);
int GetLength();
};

Thanks for your patience.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jan 11, 2006 3:28 pm 
Offline
User avatar

Joined: Wed Sep 28, 2005 8:39 am
Posts: 9341
Location: St Augusta, MN
When you want to return an RB object, you create an instance of it, lock it, and return it. Like this:

REALobject obj = REALnewInstance( someClassPointer );
REALLockObject( obj );

return obj;


The plugins sdk has some documentation included in it that describes these functions in more detail.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group