Published on InterSystems Developer Community (https://community.intersystems.com)

主页 > Object Script基础知识(五)

文章
Jingwei Wang · 六月 6, 2022 阅读大约需 1 分钟

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 ReturnType
Method FindPerson(id As %String) As Person 
{
Set person = ##class(Person).%OpenId(id) 
Quit person
}

 

  • 类的重命名

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

 

#ObjectScript #Caché #Ensemble #InterSystems IRIS

源 URL:https://cn.community.intersystems.com/post/object-script%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E4%BA%94