[VSDK ] Access to cursor fields
Eric Forget
forgete at cafederic.com
Thu Jan 23 17:07:31 CST 2003
> By the way, anybody have idea how to access VALUES of fields of cursor
> In more short way ?
>
> I consider in 2.0 provide as alternative cursor with binding to true C++
> variables (old know way). Underline as alternative. So each can choose what
> is better for him.
>
> But may be something else ?
Yep it is possible. I don't remember the name of this method which I read 2
years ago in Modern C++ Design (from Andrei Alexandrescu).
What we want is this:
short myShort = curs->GetValue("Field1");
char *myCharPtr = curs->GetValue("Field2");
long myLong = curs->GetValue("Field3");
For this to work there is a simple trick. You cannot have overloading of
functions which differ only by return code. However, you can return a
temporary object instead:
class VDK_TempReturnValue
{
public:
VDK_TempReturnValue(
VDK_Cursor &inCursor,
const char* inFieldName)
: mCurs(inCursor), mName(inName) {}
operator short() const
{
VDK_Short* field = mc->GetShortField(mName);
return (short)*field;
}
operator long() const
{
VDK_Long* field = mc->GetLongField(mName);
return (long)*field;
}
operator char *() const
{
VDK_Text* field = mc->GetTextField(mName);
return (char *)*field;
}
protected:
VDK_Cursor &mCurs;
const char * mName;
};
And then for your VDK_Cursor:
class VDK_Cursor
{
public:
VDK_TempReturnValue GetValue(const char* inName) const
{
return VDK_TempReturnValue(*this, inName);
}
};
You will have to support GetValue(ushort index) too, but I think you get the
idea...
Éric
___________________________________________________________________
Eric Forget Cafederic
ForgetE at cafederic.com <http://www.cafederic.com/>
Fingerprint <86D5 38F5 E1FD 5D9C 71C3 BAA3 797E 70A4 6210 C684>
More information about the Valentina
mailing list