获取/设定对象的属性值
在事件过程中可以通过使用以下API访问对象的属性。
函数 | 功能 |
mpfc::WSCvariant mpfc::WSCbase_getProperty() | 获取属性值 |
mpfc::WSCvariant mpfc::WSCbase_setProperty() | 设定属性值 |
获取属性值
通过WSCbase类的成员函数getProperty()获取对象的属性值。
#----------------------------------------------------------
#Function for the event procedure
#----------------------------------------------------------
use mpfc;
sub event_procedure {
my ($object) = @_;
# 获取"x" (X坐标)属性值的字符串表示
$x = mpfc::WSCbase_getProperty($object,"x");
printf("x=%s\n",mpfc::WSCvariant_getCharPtr($x)); # 获得字符串
# 获取"y" (Y坐标)属性值
$y = mpfc::WSCbase_getProperty($object,"y");
printf("y=%d\n",mpfc::WSCvariant_getLong($y)); # 获得 long 类型值
}
1;
在获取"x"属性值的例子中,得到的属性值是字符串类型。在获取"y"属性值的例子中,
获得数值型属性值。由于函数getProperty()的返回值是WSCvariant 类型,可以获得
各种类型的值。
mpfc.WSCvariant 取值函数 | 功能 |
mpfc::WSCvarinat_getChar() | 获取 char 型值 |
mpfc::WSCvarinat_getUnsignedChar() | 获取 unsigned char 型值 |
mpfc::WSCvarinat_getShort() | 获取 short 型值 |
mpfc::WSCvarinat_getUnsignedShort() | 获取 unsigned short 型值 |
mpfc::WSCvarinat_getLong() | 获取 long 型值 |
mpfc::WSCvarinat_getUnsignedLong() | 获取 unsigned long 型值 |
mpfc::WSCvarinat_getInt() | 获取 int 型值 |
mpfc::WSCvarinat_getUnsignedInt() | 获取 unsigned int 型值 |
mpfc::WSCvarinat_getFloat() | 获取 float 型值 |
mpfc::WSCvarinat_getDouble() | 获取 double 型值 |
mpfc::WSCvarinat_getCharPtr() | 获取 char* 型值 |
设定属性值
通过WSCbase类的成员函数setProperty()设定对象的属性值。
#----------------------------------------------------------
#Function for the event procedure
#----------------------------------------------------------
use mpfc;
sub event_procedure {
my ($object) = @_;
# 通过字符串设定"x"(X坐标)属性值
$x="100";
mpfc::WSCbase_setProperty($object,"x",$x);
# 设定"y"(Y坐标)属性值
$y=100;
mpfc::WSCbase_setProperty($object,"y",$y);
return;
}
1;
在设定"x"属性值的例子中,通过字符串类型设定属性值。
而在设定"y"属性值的例子中,通过整数类型设定属性值。
根据属性值更新对象
通常,在事件过程执行完毕后立即更新对象。如果需要在修改属性值后
立即更新对象,通过调用update()、draw()和redraw()函数来实现。
在不同的窗口系统更新对象时,存在不能立即更新的情况(例如X11系统等)。
此时,请调用WSDappDev类的update()方法。
#----------------------------------------------------------
#Function for the event procedure
#----------------------------------------------------------
use mpfc;
sub event_procedure {
my ($object) = @_;
mpfc::WSCbase_getProperty($newvlab_001,"labelString","text");
mpfc::WSCbase_update($newvlab_001); # 直接更新对象
mpfc::WSDappDev_update(mpfc::WSGIappDev()); # 向窗口系统提出更新要求
mpfc::WSCbase_getProperty($newvlab_002,"labelString","text");
mpfc::WSCbase_update($newvlab_002); # 直接更新对象
mpfc::WSDappDev_update(mpfc::WSGIappDev()); # 向窗口系统提出更新要求
return;
}
1;