I.T. Discussion Community!
-Collapse +Expand
Paradox
Search Paradox Group:

Advanced
-Collapse +Expand Paradox To/From
To/FromCODEGuides
-Collapse +Expand Paradox Store
PRESTWOODSTORE

Prestwood eMagazine

February Edition
Subscribe now! It's Free!
Enter your email:

   ► KBDesktop Data...Paradox & Ob...   Print This     
  From the August 2014 Issue of Prestwood eMag
 
Paradox & ObjectPAL:
ObjectPAL Array (Array[] type)
 
Posted 9 years ago on 3/29/2010
Paradox Code Snippet:
 A flashcard from our Paradox Flashcards Library
 A code snippet from our Paradox Code Snippets Page
 Tags: ObjectPAL , Array

KB102138



Languages Focus: Array

A data structure in which individual values (called elements or items) may be located by reference to one or more integer index variables, the number of such indices being the number of dimensions in the array.

Arrays can start with an index value of 0 or 1, sometimes referred to as 0 based or 1 based.

ObjectPAL Array

Arrays in ObjectPAL use a 1-based subscript (also known as an index). Use [] with a subscript to refer to an element (i.e. MyArray[1], MyArray[2]).

The number of elements for a given array in ObjectPAL are either fixed or resizeable. Specify the size when you declare it for fixed. Use size() to get the number of elements, size() returns 0 if the array has no elements. Use setSize(), grow(), addLast(), etc. to add elements to an array.

Syntax Example:

var
  MyArray Array[4] String ;Fixed size array.
  i LongInt
endVar

MyArray[1] = "Mike"
MyArray[2] = "Lisa"
MyArray[3] = "Felicia"
MyArray[4] = "Nathan"

if MyArray.size() > 0 then
  for i from 1 to MyArray.size()
    msgInfo("", MyArray[i])
  endFor
endIf

The above example, is an example of a fixed size array in which you specified the size of the array when declared:

MyArray Array[4] String

Resizeable Arrays

With a resizeable array, you can set an initial size of the array and grow it as needed:

var
  MyArray Array[] String ;Resizeable array.
  i LongInt
endVar
  
MyArray.setSize(3)       ;Set initial size.
  
MyArray[1] = "Mike"
MyArray[2] = "Lisa"
MyArray[3] = "Felicia"
  
MyArray.setSize(4)      ;Reset size (truncates if you set smaller.)
MyArray[4] = "Nathan"
  
MyArray.Grow(1)         ;Add to the array with grow.
MyArray[5] = "Ingo"

if MyArray.size() > 0 then
  for i from 1 to MyArray.size()
    msgInfo("", MyArray[i])
  endFor
endIf

More Info


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1182A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Intermediate

1 Intermediate Level Question

Question #1: True or False?

An ObjectPAL array is 0-based, meaning, the first element has an index of 0.

Answer:
  • True
  • False

  •  KB Article #102138 Counter
    14586
    Since 3/29/2010
    -
       Contact Us!
     
    PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

    2,306 People Online Now!!  
    Sign In to see who's online now!  Not a member? Join now. It's free!
    Show more stats...


    ©1995-2019 PrestwoodBoards  [Security & Privacy]
    Professional IT Services: Coding | Websites | Computer Tech