swirl
Guide to OmniMark 7   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
  Related Syntax   Related Concepts  
operator  

cast

 

 

Syntax

  record-type-name cast record-expression


Purpose

You can use cast to force a record of an extended type that is resident on a shelf of its base type to be treated as its own type rather than the base type.

One example of when this is useful is when you call a dynamically overloaded function and then want to access fields in the record returned by that function. You know what type the result is, based on the type you passed to it, but OmniMark still treats it as a record of the base type. Here is an example:

  declare record point
   field integer x
   field integer y

  declare record pixel
   extends point
   field stream color

  define dynamic point function move-point
   value point a
   to value point b
   as
     local point c
     set c:x to b:x
     set c:y to b:y
     return c

  define overriding point function move-point
   value pixel a
   to value point b
   as
     local pixel c
     set c:x to b:x
     set c:y to b:y
     return c

  process
   local point a variable
   local pixel b
   local point c

   set b:x to 5
   set b:y to 78
   set b:color to "red"

   set c:x to 87
   set c:y to 56

   output (pixel cast move-point b to c):color

    Related Syntax
   declare record
   define overloaded function, dynamic, overridding
   do select-type
 
Related Concepts
   Records, extended
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACYLIBRARIES ] [ ERRORS ]

OmniMark 7.1.2 Documentation Generated: June 28, 2005 at 5:44:59 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © Stilo Corporation, 1988-2005.