dbTalk Databases Forums  

Demo: Invoking UDFs from UDTs

comp.databases.object comp.databases.object


Discuss Demo: Invoking UDFs from UDTs in the comp.databases.object forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Neo
 
Posts: n/a

Default Demo: Invoking UDFs from UDTs - 08-09-2004 , 04:51 PM






www.xdb2.com/Example/Ex006.asp demos how to link a user-defined C
function (DisplayInfo_r) to a class (person) and then have instances
(john, mary) invoke the inherited function.

void FunctionLinkAndInherit_Demo()
{
// Create person in db.
int* pPerson = T_create();
T_Name_relate(&pPerson, _T("person"));
T_relate(&pPerson, &pReCls_g, &pThing_g);

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

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

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

// Create john, an instance of person.
// Set his age to 35.
int* pJohn = T_create();
T_Name_relate(&pJohn, _T("john"));
T_relate(&pJohn, &pReCls_g, &pPerson);
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_Name_relate(&pMary, _T("mary"));
T_relate(&pMary, &pReCls_g, &pPerson);
T_Val_relate(&pMary, &pAge, _T("25"));
T_Val_relate(&pMary, &pColor, _T("brown"));

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

// Have john execute function displayInfo
// which he inherits from his class (person).
// Following displays "john cls person. 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 cls person. 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[kStrSz_g+1] = _T("");
T_Name_get(pT, sT, kStrSz_g);

BOOL hasProperty_b = FALSE;
TCHAR sInfo[kStrSz_g+1] = _T("");
int* pA[] = {NULL, pT, pS_g, NULL};
int* pB[] = {NULL, (int*)pA, pN_g, NULL};
while (int* pN=X2(pB)){
if (pReName_g != N_getV(pN)){
hasProperty_b = TRUE;

TCHAR sProp[kStrSz_g+1] = _T("");
T_Name_get(N_getV(pN), sProp, kStrSz_g);

TCHAR sVal[kStrSz_g+1] = _T("");
T_Name_get(N_getO(pN), sVal, kStrSz_g);

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

_tcscat(sInfo, sSent);
}
}

if (hasProperty_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:
1. Select thing/person/john.
2. Ctrl+E (execute).
3. Select thing/function/displayInfo or thing/person/displayInfo.
4. Ctrl+V (paste).

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.