ooPIC Logo

Object Declaration

Main Index
Language Idx
Back to top of pageDescription:
 An Object Declaration is a compiler directive that declares Objects for use and allocates storage space in RAM for the Object's instance.  A subscript value may be specified to optionally create an array of Objects.
Back to top of pageSyntax:
 The following shows the format of the Object Declaration syntax.
Visual Basic
Dim <id>[(<sub>)] As [New] <type>[(init)]
Basic
<id>[(<sub>)] As <type>[(init)]
C
<type> <id>[[<sub>]] [= New <type>[(init)]];
Java
<type> <id>[[<sub>]] [= New <type>[(init)]];

The following table lists the elements of the Object Declaration Statement syntax.
ElementDescription
<id>Name of the Identifier for the new Object. Follows standard naming conventions.
<sub>Optional dimension of an array. May be any positive numeric value but no expressions are allowed
<type>The type of Object to create an instance of. May be one of the Objects listed in the Object List.
<init>A list of arguments used to initialize the object's properties.

Back to top of pageOperation:
 During compilation:
When a Object Declaration is encountered in the program's source code, the identifier specified by the <id> element is added to a list of Objects. The program's source code then references this Object by its identifier. If a <sub> value is specified, an array of that Object type is created. The program code references each Object in an array by the same identifier but distinguishes between them by a subscript value.

During execution:
When a Object Declaration is encountered in the program's executable code, space is allocated in RAM memory in which a new instance of the Object specified by the <type> element is created at which time, all properties of that Object are set to 0, unless otherwise noted by the Object's specifications.

Back to top of pageRemarks:
 Objects can also be declared that are aliases of objects that already exists.  The syntax is identical to the syntax used in basic except that instead of specifying a class, an existing object is specified.  Note that an array of aliases cannot be created in this manner.

The following shows the format of the Object aliasing syntax.
Visual Basic
Dim <id> As <existingobject>
Basic
<id> As <existingobject>

Back to top of pageExample:
 In the following example program, 3 new Objects instances are created and used.
The first statement creates a new instance of the 8-bit Variable Object oByte with the name "NumOfPresses".
The second statement creates a new instance of a oDIO1 Hardware Object with the name "RedWire".
The third statement creates 3 new instances of the 8-bit Variable Object oByte with the name "Thing".
In the remaining lines, all of the Objects are referenced.
Visual BasicC & Java
Dim NumOfPresses As New oByte
Dim RedWire As New oDIO1
Dim Thing(3) As New oByte

Sub Main()
  If RedWire.Value = cvOn Then
    Thing(1).Value = 27
    Thing(2).Value = 37
    Thing(3).Value = NumOfPresses
  End If
End Sub
oByte NumOfPresses = New oByte;
oDIO1 RedWire = New oDIO1;
oByte Thing[3] = New oByte;

Void Main(Void){
  If (RedWire.Value = cvOn){
    Thing[1].Value = 27;
    Thing[2].Value = 37;
    Thing[3].Value = NumOfPresses;
  }
}
Basic 
NumOfPresses As oByte
RedWire As oDIO1
Thing(3) As oByte

If RedWire.Value = cvOn Then
  Thing(1).Value = 27
  Thing(2).Value = 37
  Thing(3).Value = NumOfPresses
End If
 

The following example shows an Object Declaration creating 3 Objects of the same type.
Visual BasicC & Java
Dim A As New oByte, B As New oBit
oByte A = New oByte; 
oBit B = New oBit;
Basic 
A As oByte, B As oBit
 

The following example shows an Object Declaration that creates an array of 12 oServo Objects with the name "Leg".
Visual BasicC & Java
Dim Leg(12) As New oServo
oServo Leg[12] = New oServo;
Visual Basic 
Leg(12) As oServo
 

The following example shows an Object Declaration that creates an alias to a motor's speed.
Visual Basic / Basic
M As oDCMotor
S As M.Speed

Back to top of pageVersion History and Bug List:
 Firmware Ver A1: Introduced.

Bugs: No known bugs.


 

ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.