I got sick of all the DmGetRecord(), MemHandleLock, MemHandleUnlock,
DmReleaseRecord I was doing, so I wrote the
class you'll find at the end of this message.  This class is going to be
part of a shared library - there is a problem linking it.

I get: Link Error   : Scripts.cpp: 'operator delete(void*)' referenced from
'CData<SomeStructure>::~CData()' is undefined.

Now this is ok - I know that the error is caused because I'm not linking in
the C++ runtime.

I do have a question about this

Why am I not getting an error for 'new' too?

(Before you ask, the only use of CData is static, so I can kind of figure
out why there is no new, but there
shouldn't be a delete either in this case?)


---------8<-----------------8<-----------------8<-----------------8<--------
---------8<--------

template<class T> class CData
{
private:
        VoidHand h;
        VoidPtr p;
        DmOpenRef rDB;
        int iRec;
        Boolean bWrote;
        CData(); // private & no implementation - must use other constructor
public:
        CData(const DmOpenRef& r, int i);
        ~CData();
        T* Data() { return (T*)p; }
        virtual Err Write(VoidPtr ptr, int iOffset = 0, int iLen = sizeof(T),
Boolean bMod = true);
        Boolean IsModified() { return bWrote; }
};

template<class T> CData<T>::CData(const DmOpenRef& r, int i) : rDB(r),
iRec(i), bWrote(false)
{
        h = DmGetRecord(rDB, i);
        p = MemHandleLock(h);
}

template<class T> CData<T>::~CData()
{
        MemHandleUnlock(h);
        DmReleaseRecord(rDB, iRec, bWrote);
}

template<class T> Err CData<T>::Write(VoidPtr ptr, int iOffset, int iLen,
Boolean bMod)
{
        if (!DmWrite(p, iOffset, ptr, iLen))
        {
                bWrote |= bMod; // can't unmodify
                return 0;
        }
        return DmGetLastErr();
}


Reply via email to