- E.Y. Harburg
#===================================================================================================
# Example Script: Aztec "Using Arrays" Script
# Demonstrates use of Aztec arrays, dynamically allocating, and automatially resizing.
#===================================================================================================
# Main class that is derived from Thread. VM automatically creates us and executes Run().
method Main()
{
data<int> Count
data<int> ArraySize = 10
data<string> StringArray[5] # Array created automatically by system.
data<SimpleBaseClass[]> BaseArray # Array must be manually created at run-time.
data<SimpleBaseClass[]> InitBaseArray = { new<SimpleClass1("Array_101")>,
new<SimpleClass1("Array_102")>,
new<SimpleClass1("Array_103")> } # Array also created automatically.
# Make the string array be "auto resizable" and then jam ten items into it.
StringArray.SetAutoResize()
iterate ( Count in 1..ArraySize )
{
StringArray[Count] = "Text string for array element " + Count.Str()
StdIO.Write(StringArray[Count])
}
# Allocate the array and then sit in loop and allocate elements of the array.
BaseArray = new<SimpleBaseClass[ArraySize]>
iterate ( Count in 1..BaseArray.Size() )
{
# Allocate element (of a real class derived from the base) and put it into the array.
BaseArray[Count] = new<SimpleClass1("Array_" + Count.Str())>
}
# Send the two "base arrays" arrays to another method to dump out the contents.
DumpBaseArray(BaseArray)
DumpBaseArray(InitBaseArray)
}
# This method takes an array and writes out the contents.
method DumpBaseArray(SimpleBaseClass[] BaseArray)
{
data<int> Count
iterate ( Count in 1..BaseArray.Size() )
{
# Write out the name of this element.
StdIO.Write("Element name from array is " + BaseArray[Count].GetName())
}
}
#--------------------------------------------------------------------------
# Simple class hierarchy to use for array demonstration. There is an
# abstract base class and one class derived from that base.
#--------------------------------------------------------------------------
class SimpleBaseClass
{
method<string> abstract GetName()
}
# This class is derived from abstract SimpleBaseClass and overrides GetName().
class SimpleClass1 from<SimpleBaseClass>
{
method SimpleClass1(string Name)
{
ClassName = Name
}
method<string> virtual GetName()
{
return("SimpleClass1->" + ClassName)
}
data<string> ClassName
}