CopyField Method for LCFieldlist

This method copies an existing field and inserts a copy of the field within a fieldlist at a specified position.

Defined In

LCFieldlist

Syntax

Set newField = fieldList. CopyField (index, srcField, name)

Parameters

Parameter

Description

index

Long, in the range 1 to (fieldList.FieldCount + 1). Position to insert the new field into the list. You may insert into the middle of the list, which will not overwrite an existing field.

srcField

LCField. The source field to copy.

name

String. The name to give the copy of the field.

Return Value

Value

Description

newField

LCField. The new copy of srcField.

Example

Option Public
Option Explicit
Uselsx "*lsxlc" 
Sub Initialize
  Dim fldLstRecord As New LCFieldList
  Dim fld As New LCField (LCTYPE_TEXT)
  Dim ref As LCField
  Dim text As String
  ' There are a number of ways to build a fieldlist
  ' Append will add a field to a list given a type
  Set ref = FldLstRecord.Append ("ACCOUNTMANAGER", LCTYPE_INT)
  Set ref = FldLstRecord.Append ("COMPANYID", LCTYPE_INT)
  ' Insert is like Append but the position within
  ' the fieldlist must be specified
  Set ref = FldLstRecord.Insert (1, "COMPANYADDRESS", LCTYPE_TEXT)
  ' CopyField will add a field to a list
  ' using an existing field as a template
  fld.Flags = LCFIELDF_KEY
  Set ref = FldLstRecord.CopyField (1, fld, "CONTACTNAME")
  ' IncludeField will add an existing field to a list,
  ' making it part of the list. In this case, 'fld'
  ' becomes a reference into the fieldlist
  fld.Flags = 0
  Call FldLstRecord.IncludeField (3, fld, "COMPANYCITY")
  text = ""
  Forall fieldname In FldLstRecord.Names
    If Text = "" Then text = fieldname Else text = text + ", " + fieldname
  End Forall
  Print "The field list looks like: " & text
End Sub

Example Output

The field list looks like: 
CONTACTNAME, COMPANYADDRESS, COMPANYCITY, ACCOUNTMANAGER, COMPANYID