![]() |
How to acccess a value of the property of the instanceIn the event program, you can access the property of the instance by the method: get/setProperty().
How to get a value of the propertiesYou can get a value of the property by the method of WSCbase: getProerty().void event_procedure(WSCbase* object){ //To get a value of the property: WSNx by string type. WSCstring x = object->getProperty(WSNx); printf("x=%s\n",(char*)x); //To get a value of the property: WSNy by short type. short y = object->getProperty(WSNy); }In the example of WSNx, it gets a value by string type. The WSCstring type manages the buffer of the string automatically, so there is no need to manage it by programmer. In the example of WSNy, it gets a value by short type. The method: getProperty() returns a value by WSCvariant type. The WSCvariant type can convert the various kind of type automatically. The following example is a some conversion short type into string type. void cbop(WSCbase* object){ //To get a value of the property: WSNx by string type. WSCstring x = object->getProperty(WSNx); printf("x=%s\n",(char*)x); //To get a value of the property: WSNy by short type. short y = object->getProperty(WSNy); //convert into string.. WSCvariant stry = y; printf("y=%s\n",(char*)stry); //convert into double. printf("y=%fl\n",(double)stry); }Notice: You can not get the value by char*,if you use it,the pointer will be junc pointer when the method of WSCbase: getProperty() will be done, because the returned value is auto variable of the WSCvariant, so the WSCvariant instance and its internal buffer for string is destroyed when the method is done. If you want to get the char* pointer, see the following program. void event_procedure(WSCbase* object){ //To get a value of the property: WSNlabelString by char pointer. //Not good! the poiter string will be junc pointer! char* string = object->getProperty(WSNlabelString); //To get a value of the property: WSNlabelString by char pointer. //Good example. The string1 (WSCstirng instance) keeps the string buffer. WSCstring string1 string1 = object->getProperty(WSNlabelString); char* str = (char*)string1; } Setting of propertyYou can set a value to the property by the method of WSCbase: setProerty().void event_procedure(WSCbase* object){ //To set a value to the property: WSNx by string type. char* x="100"; object->setProperty(WSNx,x); //To set a value to the property: WSNy by short type. short y=100; object->getProperty(WSNy,y); }In the example of WSNx, it sets a value by string type. In the example of WSNy, it sets a value by short type. The parameter of the method: setProperty() is WSCvariant type, so it converts the value automatically. Updating the instance to refrect the changed valueUse the method: update(),draw(),redraw() to update the instance to refrect the canged value.obj1->getProperty(WSNlabelString,"string1"); obj1->update(); //updates the instance obj2->getProperty(WSNlabelString,"string2"); obj2->update(); //updates the instanceUsually, it updates automatically when the event procedure is done, but if you want to update right away,you can use the method: update(),draw(),redraw(). The method: update() or draw() updates the instance if needed, but redraw() updates compulsory. Document Release 3.0 For Use with Wide Studio Release 3.0, Summer 2002
|