Attribute Macro pbni_codegen::nonvisualobject [−][src]
#[nonvisualobject]
Expand description
生成不可视对象
Parameters
name
: 映射的PB对象类名 (默认为Rust对象名)inherit
: 继承的对象 (此对象的字段)
Notice
继承模式不支持覆盖(override)方法实现,并且在PB端需要将父类的方法声明在子类中重新声明
Examples
- PowerBuilder
/* 父类声明 */
forward
global type n_parent from nonvisualobject
end type
end forward
global type n_parent from nonvisualobject native "pbrs.dll"
public function string of_hello (string world)
end type
global n_parent n_parent
type variables
end variables
on n_parent.create
call super::create
TriggerEvent( this, "constructor" )
end on
on n_parent.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
/* 子类声明 */
forward
global type n_child from n_parent
end type
end forward
global type n_child from n_parent native "pbrs.dll"
// 重新声明父类方法
public function string of_hello (string world)
// 声明子类私有的方法
public function string of_foo (string bar)
end type
global n_child n_child
type variables
end variables
on n_child.create
call super::create
TriggerEvent( this, "constructor" )
end on
on n_child.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
- Rust(pbni-rs)
struct RustObject { session: Session, ctx: ContextObject } #[nonvisualobject(name = "n_pbni")] impl RustObject { #[constructor] fn new(session: Session, ctx: ContextObject) -> RustObject { RustObject { session, ctx } } #[method(name="of_Hello")] fn hello(&self, world: String) -> String { format!("hello {}!",world) } } struct RustChildObject { parent: RustObject } #[nonvisualobject(name = "n_pbni_child", inherit = "parent")] impl RustChildObject { #[constructor] fn new(session: Session, ctx: ContextObject) -> RustChildObject { RustChildObject { parent : RustObject { session, ctx } } } #[method(name="of_Foo")] fn foo(&self, bar: String) -> String { format!("foo {}!",bar) } }