作者

Sales Engineer at InterSystems
文章 Jingwei Wang · 六月 6, 2022 1m read

Object Script基础知识(五)

Object Script(五)

  • 在类中定义属性

Property PropName as Classname(PARAM1=value,PARAM2=value) [ Keywords ] ;
Property SSN As %String(PATTERN = "3N1""-""2N1""-""4N") [ Required ];

 

  • 创建函数示例

Studio创建:

将下段代码填写入建好的类中:

ClassMethod FindPatient(id As %String) As HIS.Patient{  Set patient= ##class(HIS.Patien).%OpenId(id)        Quit patient}

 

Terminal 调用:

set p = ##class(HIS.Patient).FindPatient(1)

 

  • 参数

传入参数的类型分为普通参数,输出型参数和返回参数:

普通参数 (传值参数):

Method Calculate(count As %Integer, name, state As %String = "CA") {…}

 

输出型参数(引用) :

Method Swap(ByRef x As %Integer, ByRef y As %Integer) { Set temp = x Set x = y Set y = temp }D ##class(myclass).Swap(.x,.y)

 

返回参数

Method MethodName() As ReturnTypeMethod FindPerson(id As %String) As Person {
Set person = ##class(Person).%OpenId(id) Quit person
}

 

  • 类的重命名

包名、类名不能修改,可以用Tools ->Class Copy