Monday, July 28, 2008



PeopleCode Snippets

Downcasting class variable



If the downcast operator is to be used in the context of further object expressions (such as references to other members using dot notation) then the downcast must be enclosed in parentheses to emphasize that the downcast happens before the member reference.

class Fruit



property number FruitCount;



end-class;







class Banana extends Fruit



property number BananaCount;



end-class;



In the following code example, first the variables are assigned. All the variable assignments are legal, for Banana is a subtype of Fruit.

local Banana &MyBanana = Create Banana();



local Fruit &MyFruit = &MyBanana; /* okay, Banana is a subtype of Fruit */



local number &Num = &MyBanana.BananaCount;



The next two lines of code don't produce an error, as &MyFruit is currently a Banana at runtime.

&MyBanana = &MyFruit as Banana;



&Num = (&MyFruit as Banana).BananaCount; /* same as &MyBanana.BananaCount */



In the next lines of code, we're reassigning &MyFruit to be of type Fruit, that is, of the superclass Fruit. When you try to reassign &MyFruit as Banana, &MyBanana is assigned as Null, because &MyFruit is no longer of type Banana.

&MyFruit = Create Fruit();







&MyBanana = &MyFruit as Banana; /* assigns Null - &MyFruit isn't a Banana */









Field.LongTranslateValue

You cannot access the &VALUE = &MYFIELD.LongTranslateValue; unless you have the following set as the record field properties.

Without the edits being set the above LongTranslateValue property will return the small translate value.