LCFieldlist の CopyField メソッド

このメソッドは、既存のフィールドをコピーし、フィールドのコピーをフィールドリストの指定された位置に挿入します。

定義位置

LCFieldlist

構文

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

パラメータ

パラメータ

説明

index

Long。1 ~ (fieldList.FieldCount + 1) の値です。新規フィールドを挿入するフィールドリスト内の位置です。リストの途中にフィールドを挿入できます。このとき、既存フィールドは上書きされません。

srcField

LCField。コピーするフィールドです。

name

String 型。フィールドのコピーに付ける名前です。

戻り値

説明

newField

LCField。srcField の新しいコピーです。

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

出力例

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