Cache ver 5.0.0 A class is created using %Dictionary.ClassDefinition class
s cdef=##class(%Dictionary.ClassDefinition).%New(aPackage_"."_aClassName) s cdef.ClassType="persistent" s cdef.Super="%Persistent" s cdef.ProcedureBlock=1 d cdef.%Save() s pdef=##class(%Dictionary.PropertyDefinition).%New() d cdef.Properties.Insert(pdef) s pdef.Name="pName" s pdef.Type="%String" d cdef.%Save() d pdef.%Close() s pdef=##class(%Dictionary.PropertyDefinition).%New() d cdef.Properties.Insert(pdef) s pdef.Name="pType" s pdef.Type="%String" d cdef.%Save() d pdef.%Close() etc........ 1. The above works fine. However, the code shown in the documentation seems to be incorrect. http://127.0.0.1:1972/csp/docbook/DocBook.UI.Page.cls?KEY=GOBJ_classdef#GOBJ _C2551 Set cdef = ##class(%Dictionary.ClassDefinition).%New("MyApp.MyClass") Set cdef.Persistent = 1 Set cdef.Super = "%Persistent,%Populate" // add a Name property Set pdef = ##class(%Dictionary.PropertyDefinition).%New("MyClass.Name") Do cdef.Properties.Insert(pdef) Set pdef.Type="%String" // save the class definition object Do cdef.%Save() a) This seems to be from legacy documentation of version 4.X.X and earlier.It does not work b) No arguments are accepted for %New method of the %Dictionary.PropertyDefinition class. c) The Persistent property of the %Dictionary.ClassDefinition class does not exist. Instead there is a ClassType property. See above. 2. But it seems there is a bigger bug when creating methods using %Dictionary.ClassDefinition class. Continuing the above working code s mdef=##class(%Dictionary.MethodDefinition).%New() d cdef.Methods.Insert(mdef) s mdef.Name="mCompCode" s mdef.ReturnType="%String" s mdef.FormalSpec="aID:%Integer" s cmcode=" s mx=##class("_aPackage_"."_aClassName_").%OpenId(aID)"_$C(13,10) s cmcode=cmcode_" s mx.pParentRef.pCode_mx.pCode"_$C(13,10) s cmcode=cmcode_" d mx.%Close()"_$C(13,10) s cmcode=cmcode_" q vCode"_$C(13,10) d mdef.Implementation.Write(cmcode) s mdef.ClassMethod=1 d cdef.%Save() d mdef.%Close() a) This works fine. But if you try and create two or more methods one after the other (continuation) s mdef=##class(%Dictionary.MethodDefinition).%New() d cdef.Methods.Insert(mdef) s mdef.Name="mCalAge" etc... b) The code in the first method gets deleted All other attributes of the method are saved.. c) There is no change in the fact that the code is gettng deleted, even by # Interchanging the order of the method # Compiling the class after creating one method and then creating the second method. # Separating the two method creation codes in different COS methods. # Using different oref (cdef and rdef, mdef and ndef), There are no such problems using %Library.ClassDefinition and its related classes. Everything works fine. Has anybody noticed this ? Or Am I doing something wrong or missing something ? -- Sukesh Hoogan e-Compact Enterprise Solutions Bombay, India http//personal.vsnl.com/sukesh_hoogan (updated : March 18, 2004)
