dOPC Client Toolkit Help file
TdOPCItems.AddItem Method
C++
public: virtual __fastcall TdOPCItem AddItem(
    AnsiString ItemId, 
    boolean later = false
);
C#
public TdOPCItem AddItem(
    String ItemId, 
    boolean later
);
Visual Basic
Public Function AddItem(
    ItemId As String, 
    later As boolean = false
) As TdOPCItem

AddItem creates and returns a new TdOPCItem object and adds it to the Items collection.

The properties of this new item are determined by the current defaults in the TdOPCGroup object. After an item is added its properties can be modified. The name of the item is passed by the ItemId parameter. This method is intended to provide the mechanism to add one item at a time to the collection. To reduce the DCOM calls it is possible to add multiple items, therefore the parameter <later> has to be set to True and the OPCAddALLItems method has to be called (see also last example below).

var
  Group : TdOPCGroup;
  V3    : TdOPCItem;
begin
  Group := OPCServer.OPCGroups.Add('MyGroup');  //first add a group
  Group.DefaultItem.IsActive := false;          //override defaultvalue
  Group.OPCItems.AddItem('test.test.value1');   //adds a new Item to Group
  Group.OPCItems.AddItem('test.test.value2');
  V3 := Group.OPCItems.AddItem('test.test.value3');
  V3.IsActive := true;
end;
  
If you want to add more than one OPC item it is better
to use the methods BeginUpdate and EndUpdate of class TdOPCItems
or set parameter <later> of method AddItem to true.
The advantage of this method is that you can add OPC items to the
OPC server with only one COM/DCOM call. This has a performance advantage
against method above. Here an example:
  
procedure TForm1.Button1Click(Sender: TObject);
var
  Group : TdOPCGroup;
  V3    : TdOPCItem;
begin
  Group := OPCServer.OPCGroups.Add('MyGroup'); //first add a group
  
  Group.OPCItems.BeginUpdate;
  try
    Group.OPCItems.AddItem('test.test.value1'); //add a new Item to Group
    Group.OPCItems.AddItem('test.test.value2');
    //...
  finally
    Group.OPCItems.EndUpdate;
    Group.OPCItems.OPCAddAllItems;
  
  end;
end;
  
or
  
procedure TForm1.Button1Click(Sender: TObject);
var
  Group : TdOPCGroup;
  V3    : TdOPCItem;
begin
  Group := OPCServer.OPCGroups.Add('MyGroup'); //first add a group
  Group.OPCItems.AddItem('test.test.value1',true); //add a new Item to Group
  Group.OPCItems.AddItem('test.test.value2',true);
  Group.OPCItems.OPCAddAllItems;
end;
  
  
  
  
What do you think about this topic? Send feedback!
Copyright © 2001-2014 Kassl GmbH (http://www.kassl.de). All rights reserved.