Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Linking Function to a Thing in XDb1

 
   Database Help (Home) -> Object-Oriented RSS
Next:  OBJECT & REFERENCES  
Author Message
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 1) Posted: Sun Jun 13, 2004 1:22 pm
Post subject: Linking Function to a Thing in XDb1
Archived from groups: comp>databases>object (more info?)

/********************************************************************
The following demos how to link a C function (DisplayInfo_r) to a
class (person) and then have future instances (john, mary) of the
class invoke the inherited function. Classes and instances are things
in db.
********************************************************************/
void FunctionLinkAndInherit_Demo()
{
// Create person in db
int* pPerson = T_create();
T_relate(&pPerson, rCls, &pThing_g);
T_Name_relate(&pPerson, _T("person"));

// Link a C function (DisplayInfo_r) to person in db
T_Fn_relate(pPerson, DisplayInfo_r, _T("displayInfo"));

// Create age in db
int* pAge = T_create();
T_relate(&pAge, rCls, &pThing_g);
T_Name_relate(&pAge, _T("age"));

// Create color in db
int* pColor = T_create();
T_relate(&pColor, rCls, &pThing_g);
T_Name_relate(&pColor, _T("color"));

// Create john, an instance of person.
// Set his age to 35.
int* pJohn = T_create();
T_relate(&pJohn, rCls, &pPerson);
T_Name_relate(&pJohn, _T("john"));
T_Val_relate(&pJohn, &pAge, _T("35"));

// Create mary, an instance of person.
// Set her age to 25, and color to brown.
int* pMary = T_create();
T_relate(&pMary, rCls, &pPerson);
T_Name_relate(&pMary, _T("mary"));
T_Val_relate(&pMary, &pAge, _T("25"));
T_Val_relate(&pMary, &pColor, _T("brown"));

// Get thing for function displayInfo
int* pFnDispInfo = R_Dest(Str_getDefT(_T("displayInfo")));

// Have john execute function displayInfo
// which he inherits from his class (person).
// Following displays "john is 35." in a dialog box.
T_Fn_execute_r(pJohn, pFnDispInfo);

// Have mary execute function displayInfo
// which she inherits from her class (person).
// Following displays "mary is 25. mary is brown."
T_Fn_execute_r(pMary, pFnDispInfo);
}

/********************************************************************
Displays pT's values. (ie 'john is 35. john is brown.')
If pT has no values, displays pT's name. (ie 'john')
********************************************************************/
ERR_CODE DisplayInfo_r(int* pT)
{
TCHAR sT[kNmSz_g+1] = _T("");
T_Name_get(pT, sT, kNmSz_g);

BOOL hasVals_b = FALSE;
TCHAR sInfo[kNmSz_g+1] = _T("");
int* pX = pT;
while (*(++pX)){
if (rIs == R_Type_get(pX)){
int* pVal = R_Dest(pX);

// Skip names
if (T_AncOf_b(pName_g, pVal)){
continue;
}

hasVals_b = TRUE;

TCHAR sVal[kNmSz_g+1] = _T("");
T_Name_get(pVal, sVal, kNmSz_g);

TCHAR sSent[kNmSz_g+1] = _T("");
_stprintf(sSent, _T("%s is %s.\n"), sT, sVal);

_tcscat(sInfo, sSent);
}
}

if (hasVals_b){
MessageBox(NULL, sInfo, kAppName_sg, MB_OK);
}
else{
MessageBox(NULL, sT, kAppName_sg, MB_OK);
}

return kErrNone_g;
}

To have john execute the inherited function via the GUI (v4.6.3):
1. Select thing/person/john.
2. Ctrl+E (execute).
3. Select thing/function/displayInfo.
4. Ctrl+V (paste).

For more info, see www.xdb1.com/Example/Ex006.asp

 >> Stay informed about: Linking Function to a Thing in XDb1 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
oops help - Question 1:- Describe the following with the help of examples: 1)Generalization and its role in Inheritance. 2)abstract Classes 3)State Diagrams. 4)OMT and its impact in programming. 5)future of Object Oriented languages. Qusetion2: -Identify the..

Idempotent ODBMS iterators - I am building a client/server ODBMS in Java. It occurred to me that one way of helping to guarantee the consistency of the database was to ensure that all atomic requests were idempotent -- that is, that if a particular request is performed more than..

Modelling Books (with XDb2) -

Help Understanding OODBMS' - <font color=purple> ;> 3) Are relationships recorded in the same way as in an RDB - 1:M and</font> <font color=purple> ;> M:M? I assume that program code has to place the IDs in a "table" to</font> ...

CfP Reminder: The Second Scala Workshop - Scala Days 2011 - The Second Scala Workshop ========================= Call for Papers --------------- Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates..
   Database Help (Home) -> Object-Oriented All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]