A Caché of Tips - Classes and MVBasic

11 views
Skip to first unread message

Lee Burstein

unread,
Oct 17, 2011, 3:48:03 PM10/17/11
to intersy...@googlegroups.com
Caché is an object oriented environment whose functionality has been extended to our MultiValue implementation. This support is provided 3 ways: 1) MVBasic can invoke methods in Caché classes, 2) MVBasic can be used as the language for methods and 3) MV data files can be described as a class object. Today's tip will highlight all three with future tips expanding on these.

MVBasic invoking methods in Caché classes:
We have enhanced MVBasic to use Caché classes. This becomes extremely important as the system APIs provided with Caché are all implemented as classes. These APIs provide functionality for email, web services, sockets, ftp, error objects, system information, XML etc. Class Methods can be invoked directly while instance methods must have their class instantiated first.

Many system methods return a %Status variable that has its own structure. A future tip will discuss the %Status variable and how to work with it. For now, the first character will be a 1 or 0 indicating success or failure of the method.

Please refer to the tip on Parameter Passing (Oct 11, 2011) for additional information regarding passing parameters to methods and subroutines in MVBasic.

Since the period (.) is a legitimate character for MVBasic variable names, we introduced an alternative syntax to deal with object references. In general, the syntax is:
"PackageName.ClassName"->MethodName()

For example, if you want to see what version of Caché you are currently running, use:
CRT "%SYSTEM.Version"->GetVersion()

It is possible to maintain MultiValue data via objects. You need to first instantiate a new or existing object that represents your MultiValue data, maintain the properties and save the object. For example, I want to add a new customer to my CUSTOMER file represented by the class Receivables.Customer but will only add the customer name at this point. The MVBasic code would look like:
Cust = "Receivables.Customer"->%New()
Cust->CustName = "ABC Manufacturing  Co."
Cust->ItemId = "100"
Cust->%Save()


MVBasic as the method language:
A class that you create in Caché can use MVBasic as the method language. This can be defined for the entire class or specified on a method by method basis. This also means that you can have some methods written in MVBasic while others are written in Caché Object Script (COS).

If you have several utility methods (originally written or derived from a set of existing subroutines) and wish to create a class where all methods are MVBasic by default, use the following class declaration:
Class Util.Validations Extends %RegisteredObject [ Language = mvbasic ]

If you did not declare the default language for the class to be MVBasic, but want one method to use MVBasic, declare the method as follows:
ClassMethod ZipCode(Zip) [ Language = mvbasic ]


MV Data files described as a class object
We provide a utility program, PROTOCLASS, that uses your file dictionary to establish class definition where your field names become property names. This class inherits from %Persistent, %MV.Adaptor and %XML.Adaptor providing:
Storage of your MultiValue data in MultiValue format (field, value and subvalue marks)
Object access to your MultiValue data
SQL access to your MultiValue data (associated multivalue fields become child tables)
XML access to your MultiValue data (i.e. export your record as an XML document)

Production applications will likely need to modify this class definition, perhaps adding methods (written in MVBasic or COS) or modifying property definitions (changing the SQL name of the field/property).


Caché classes (including the MultiValue ones) can be projected for use in client side programming such as .NET or java. This provides object connectivity from the client development environment directly to your MultiValue data and/or business logic.


All tips, including this one, can be viewed at https://sites.google.com/site/intersystemsmv/home/a-cache-of-tips


Lee H. Burstein
Product Manager
InterSystems
Office: 302-477-0180
Cell: 302-345-0810

Reply all
Reply to author
Forward
0 new messages