addinstance Method
Class: application
Expand/Collapse source code of procedure addinstance Source Code
LPARAMETERS toForm

*-- This routine handles multiple instances of a form
*-- A description of each element of the aInstances[] array
*-- appears below.

LOCAL lnElem, ;
      lnRow, ;
      lcFormName

lcFormName = toForm.Name
*-- Scan this.aInstances[] looking for lcFormName. If found
*-- increment the instance count for that name by 1 and
*-- return the next available instance number
lnElem = ASCAN(this.aInstances, lcFormName)
IF lnElem = 0
  *-- Expand the array if this is not the first form we're adding
  *-- to it
  IF TYPE("this.aInstances[1,1]") = "L"
    *-- There are no forms in the array
    lnRow = 1
  ELSE
    *-- Expand the array
    lnRow = ALEN(this.aInstances, 1) + 1
    DIMENSION this.aInstances[lnRow, ALEN(this.aInstances, 2)]
  ENDIF
  this.aInstances[lnRow, 1] = lcFormName    && Instance name
  *-this.aInstances[lnRow, 2] = toForm        && The instance itself
  this.aInstances[lnRow, 3] = 0              && Number of instances
  this.aInstances[lnRow, 4] = 0              && Next available instance number
ELSE
  lnRow = ASUBS(this.aInstances, lnElem, 1)
  *-- Make sure we still have an instance. If not, 
  *-- re-initialize it.
  IF TYPE("this.aInstances[lnRow, 2]") # "O" OR ;
      ISNULL(this.aInstances[lnRow, 2])
    this.aInstances[lnRow, 2] = toForm
  ENDIF
  *-- Stagger the new form's position
  toForm.Left = this.aInstances[lnRow, 2].Left + 5
  toForm.Top = this.aInstances[lnRow, 2].Top + 23

  *-- Save the current instance for next time
  *-this.aInstances[lnRow, 2] = toForm
ENDIF

*-- Increment the number of instances and the next 
*-- available instance number
this.aInstances[lnRow, 3] = this.aInstances[lnRow, 3] + 1
this.aInstances[lnRow, 4] = this.aInstances[lnRow, 4] + 1

RETURN this.aInstances[lnRow, 4]