Thanks Oktal and res2k, you helped me overcome several obstacles.  I'm  way 
ahead of the schedule I put myself on thanks to the overwhelming support of the 
community to get me unstuck from time to time.

Mathew Sutcliffe <[EMAIL PROTECTED]> wrote: Jim Sager wrote:
> class iMonsterFinder : public csObject
 > {
 > public:
 > int test;
 > };

Seems strange that a non-abstract class has a name prefixed with i.


> iMonsterFinder *m2;
 > m2->test=3;
 > m2->SetName("0monster");
> sg0->QueryObject()->ObjAdd(m2);

I presume you forgot to show the part where you initialize m2.


> void *vo2;
 > iMonsterFinder *m3=NULL;
> vo2=mw->QueryObject()->GetChild("0monster");
 > if(vo2!=NULL)
> m3=(iMonsterFinder *)vo2;
 > if(m3!=NULL) printf("%d\n",m3->test);

iObject *obj = mw->QueryObject()->GetChild("0monster");
if (obj)
{
   // Prefer to use scfQueryInterface here, but iMonsterFinder is
   // not an interface!
   iMonsterFinder *mf = (iMonsterFinder*) obj; //@@@!

   // Preferred:
   // csRef mf =
   // scfQueryInterface(obj);

   printf("%d\n", mf->test);
}

I think the problem might be your C-style cast. I'm not sure if that's 
guaranteed to return a valid pointer to your iMonsterFinder. The best 
way would be to make iMonsterFinder into an SCF interface and then use 
scfQueryInterface to get at it, as shown in my code comments.


Example with conjoined interface and implementation:

class MonsterFinder
: public scfImplementationExt1< MonsterFinder, csObject,
    scfFakeInterface >
{
public:
   SCF_INTERFACE(MonsterFinder, 0, 0, 1);
   MonsterFinder() : scfImplementationType (this) {}
   virtual ~MonsterFinder() {}
   int test;
};


Example with separate interface and implementation:

struct iMonsterFinder : public virtual iBase
{
   SCF_INTERFACE(iMonsterFinder, 0, 0, 1);
   virtual int GetTest() const = 0;
   virtual void SetTest(int) = 0;
};

class MonsterFinder
: public scfImplementationExt1
{
   int test;
public:
   MonsterFinder() : scfImplementationType (this) {}
   virtual ~MonsterFinder() {}
   virtual int GetTest() const { return test; }
   virtual void SetTest(int t) { test = t; }
};

All examples are untested, YMMV.


> csRef m2;
 > m2=new iMonsterFinder;
 > m2->test=3;
> m2->SetName("0monster"); SCF_INC_REF (m2);
> sg0->QueryObject()->ObjAdd(m2);

There you are doing IncRef on m2 twice! It doesn't even need one IncRef.

csRef m2;
m2.AttachNew(new iMonsterFinder);
m2->test = 3;
m2->SetName("0monster");
sg0->QueryObject()->ObjAdd(m2);

A new object already has a refcount of 1. The csRef constructor and 
csRef::operator= both do an IncRef, so when assigning a newly created 
object, use csRef::AttachNew, which doesn't touch the refcount. When the 
object is added to sg0, its gets an IncRef, and when your csRef m2 falls 
out of scope, its gets a DecRef, leaving the refcount at 1, which is 
correct since it is then reference by 1 bit of code, the sg0 object. 
User code shouldn't ever need to do IncRef or DecRef directly, really. 
csRef will do it all for you, in general.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]


       
---------------------------------
Choose the right car based on your needs.  Check out Yahoo! Autos new Car 
Finder tool.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]

Reply via email to