Difference between revisions of "OBJECT SETPROPERTY()"

From Recital Documentation Wiki
Jump to: navigation, search
(EXAMPLE)
 
(6 intermediate revisions by one user not shown)
Line 14: Line 14:
  
 
<input parameters>
 
<input parameters>
OBJECT objptr; /* Pointer to the object */
+
OBJECT objptr; /* Pointer to the object */
char *propertyname; /* property name to set */
+
char *propertyname; /* property name to set */
  
 
<output parameters>
 
<output parameters>
OBJARG buffer; /* pointer to an OBJARG buffer */
+
OBJARG buffer; /* pointer to an OBJARG buffer */
 +
 
 
</code>
 
</code>
 +
  
 
==DESCRIPTION==
 
==DESCRIPTION==
Line 46: Line 48:
 
DEFINE_METHOD(clsMyClass, Define)  
 
DEFINE_METHOD(clsMyClass, Define)  
 
{
 
{
    struct example_data *objectData = (struct example_data *)OBJECT_GETDATA();
+
struct example_data *objectData = (struct example_data *)OBJECT_GETDATA();
 
struct      API_EXPRESSION result;
 
struct      API_EXPRESSION result;
 
char     buffer[512];
 
char     buffer[512];
Line 54: Line 56:
 
OBJECT_GETPROPERTY(objectData->prop_objvalue, "class", buffer);
 
OBJECT_GETPROPERTY(objectData->prop_objvalue, "class", buffer);
 
rc = OBJECT_GETARG(buffer, &result);
 
rc = OBJECT_GETARG(buffer, &result);
if (result.errno == 0 && result.type == 'C'&&
+
if (result.errno == 0 && result.type == 'C' &&
 
    strcmp(result.character, "Exception") == 0) {  
 
    strcmp(result.character, "Exception") == 0) {  
 
    switch (OBJECT_GETARGC()) {
 
    switch (OBJECT_GETARGC()) {
Line 79: Line 81:
 
}
 
}
 
</code>
 
</code>
 +
  
 
==SEE ALSO==
 
==SEE ALSO==

Latest revision as of 16:44, 26 March 2009

PURPOSE

Set a property from an OBJARG formatted string


SYNONYM

None


SYNOPSIS

#include "dbapi.h"
 
OBJECT_SETPROPERTY(objptr, propertyname, buffer)
 
<input parameters>
OBJECT		objptr;			/* Pointer to the object */
char		*propertyname;		/* property name to set */
 
<output parameters>
OBJARG	buffer;			/* pointer to an OBJARG buffer */


DESCRIPTION

The OBJECT_SETPROPERTY() macro is used to set the value of a property from an OBJARG formatted string.


EXAMPLE

In the following example OBJECT_SETPROPERTY () is used to set the value of the property "class" from an OBJARG string format returned from a parameter passed to the method.

Example Recital program:

test = newobject("myclass")
// Executes method 'define' and updates two properties
? test.define("Error Message", -1000)
? "test.objvalue.errorno",test.objvalue.errorno
? "test.objvalue.message",test.objvalue.message

Example in 'C'object:

#include "dbapi.h"
 
/* Define define method */
DEFINE_METHOD(clsMyClass, Define) 
{
	struct example_data *objectData = (struct example_data *)OBJECT_GETDATA();
	struct      API_EXPRESSION result;
	char	    buffer[512];
	int	    rc;
 
	/* Check the object class */
	OBJECT_GETPROPERTY(objectData->prop_objvalue, "class", buffer);
	rc = OBJECT_GETARG(buffer, &result);
	if (result.errno == 0 && result.type == 'C' &&
	    strcmp(result.character, "Exception") == 0) { 
	    switch (OBJECT_GETARGC()) {
	    case 2: 
		rc = OBJECT_GETPARAMETER(2, &result);
		if (result.errno == 0 && result.type == 'N') {
		    OBJECT_SETARG(buffer, &result);
		    rc = OBJECT_SETPROPERTY(objectData->prop_objvalue, "errorno", buffer);
		}
 
	    case 1: 
		rc = OBJECT_GETPARAMETER(1, &result);
		if (result.errno == 0 && result.type == 'C') {
		    OBJECT_SETARG(buffer, &result);
		    rc = OBJECT_SETPROPERTY(objectData->prop_objvalue, "message", buffer);
		}
		break;
	    }
	}
 
	result.type = 'L';
	result.logical = (rc == 0 ? 'T' : 'F');  
	OBJECT_RETRESULT(&result);
}


SEE ALSO

DEFINE_CLASS(), DEFINE_METHOD(), DEFINE_PROPERTYGET(), DEFINE_PROPERTYSET(), DISPATCH_FACTORY(), DISPATCH_METHOD(), DISPATCH_PROPGET(), DISPATCH_PROPSET(), OBJECT_ASSIGN(), OBJECT_DELETE(), OBJECT_GETARG(), OBJECT_GETARGC(), OBJECT_GETDATA(), OBJECT_GETOBJECT(), OBJECT_GETPARAMETER(), OBJECT_GETPROPERTY(), OBJECT_GETTYPE(), OBJECT_GETVALUE(), OBJECT_NEW(), OBJECT_RETERROR(), OBJECT_RETPROPERTY(), OBJECT_RETRESULT(), OBJECT_SETARG(), OBJECT_SETDATA()