dOPC Client Toolkit Help file
TdOPCServer Class
public: class TdOPCServer : public TdOPCSvr;
public class TdOPCServer : TdOPCSvr;
Visual Basic
Public Class TdOPCServer
Inherits TdOPCSvr


class to connect to an OPC Server 

TdOPCServer is a component to control, browse, read and write data from an to any installed OPC Data Access (DA) 1.x, 2.x , 3.x and OPC XML DA servers.

The client has to create a TdOPCServer object first in order to get references to other objects. It contains the TdOPCGroups collection and also provides a TdOPCBrowser object. At first the ServerName has to be defined then the client can connect to the OPC Data Access Custom Interface (see the TdOPCSvr.Connect method or TdOPCSvr.Active property). Then the TdOPCServer object can be used to obtain general information about an OPC server and to create and manipulate the TdOPCGroups object or to navigate with the TdOPCBrowser.

This example shows you how simple it is to connect to an OPC server with the dOPC Client Toolkit. 

This example is based on our dOPC Simulation Server, but it's a trivial matter to change to another OPC Server.

unit Unit1;
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, dOPC, dOPCComn, dOPCIntf;

  TForm1 = class(TForm)
    dOPCServer1: TdOPCServer;
    Memo1: TMemo;
    Panel1: TPanel;
    bStart: TButton;
    procedure dOPCServer1Datachange(Sender: TObject; ItemList: TdOPCItemList);
    procedure bStartClick(Sender: TObject);
  Form1: TForm1;
{$R *.DFM}

procedure TForm1.bStartClick(Sender: TObject);
  G    : TdOPCGroup;
  dOPCServer1.Servername := 'dOPCSim.Kassl.Simulation';  // select your OPC Server
  G := dOPCServer1.OPCGroups.Add('testgroup');          // make a new group
  G.UpdateRate := 2000;                                 // update rate 2 secs
  G.OPCItems.AddItem('Random.String');                  // add new Item to group
  dOPCServer1.Active := true;                           // let's go

// data change event assigned in property inspector
procedure TForm1.dOPCServer1Datachange(Sender: TObject;ItemList: TdOPCItemList);
  i : integer;
  Item : TdOPCItem;
  for i := 0 to Itemlist.Count-1 do          // for all changed Items
     Item := ItemList[i];
     Memo1.Lines.Add(Item.ItemID+' '+Item.ValueStr);  // show Value as String

See Also

TdOPCSvr Events 
OnConnect is generated when a connection has been established with an OPC server. 
See TOnOPCDataChangeEvent
OnDisconnect is generated after a disconnect from an OPC server. 
OnError is generated if any error occurred on the OPC server. 
OnServerShutdown is generated when the OPC server plans to shut down. 
OnTimeout is generated when the connection to the OPC server has timed out.
The value of property KeepAlive must greater than zero 
OnWriteComplete is triggered if an AsyncWrite completes successfully. 
OnWriteError is triggered if an AsyncWrite fails. 
TdOPCSvr Methods 
check if connected to server -> if not then raise an exception 
Connect establishes a connection to an OPC DA server. 
Disconnect disconnects from a connected OPC server. 
GetItemProperty returns the current data value in the Value parameter for the item with the passed ItemId and the passed PropId. 
GetServerInfo provides global information about the server passed in the tServerStateRec parameter. 
Abstract method. 
GetState returns global information about the server. 
LoadFromFile loads the TdOPCSrv component from the file passed by the FromFile parameter and fills all properties, groups and items. 
LoadFromStream loads the TdOPCSrv component from the stream passed by the Stream parameter and fills all properties, groups and items. 
LookUpItemId returns an ItemID (if available) for the passed ItemID and the passed PropId. 
OPCServer returns the IdOPCDAConnection of the server. 
QueryAvailableProperties returns True if the Props parameter, representing a list of available properties on the server, could be filled for the passed ItemId, otherwise False
SaveToFile saves the TdOPCSrv component to the file passed by the ToFile parameter (including all properties, groups and items). 
SaveToStream saves the TdOPCSrv component to the stream passed by the Stream parameter (including all properties, groups and items). 
ServerTypeName returns the type of the OPC server as a string. 
Version2 returns True if the OPC server is OPC DA 2 server, otherwise False. 
Version3 returns True if the OPC server is OPC DA 3 server, otherwise False. 
TdHandleComponent Properties 
Active connects or disconnects from a OPC DA Server. 
BandWidth contains the server's bandwidth as a percentage of the available bandwidth. 
Browser contains the TdOPCBrowser object with the ability to browse through the items of an OPC DA Server. 
BuildNumber contains the build number of the OPC server. 
ClientName contains a client name registered with TdOPCSrvs. 
ComputerName contains the name of the server to which the client is connected via the Connect method. 
ConnectDelay contains the delay value used when the server connects to the underlying device. 
This is ConnectDelay, a member of class TdOPCSvr. 
CurrentTime contains the current time from the server. 
GroupCount contains the number of TdOPCGroup objects in the OPCGroups collection. 
Provides access to the window handle of the dOPC Server components (TdOPCServer and tdOPCEventServer). 
KeepAlive specify a value in milliseconds to check the OPC server accessibility 
LastUpdateTime contains the last update time from the server. 
LocaleId contains the locale id which may be used to localize strings returned from the server. 
MajorVersion contains the major part of the server version number (e.g. the "1" in version "1.32"). 
MinorVersion contains the minor part of the server version number (e.g. the "32" in version "1.32"). 
OPCGroupDefault contains the TdDefaultGroup for the server. 
OPCGroups contains the TdOPCGroups for the server. 
OPCGUICount contains the number of items linked with a visible component. 
Params contains additional parameters for XML communication. 
Protocol contains the communication protocol of the OPC DA server (coCOM or coXML). 
ServerCaption contains the name of the server. 
ServerClsId contains the class id of the OPC server if the Protocol is coCOM, otherwise an empty string. 
ServerName contains the name of the OPC DA server the client wants to connect with. 
ServerState contains the current server state. 
ServerStateStr contains the ServerState as a string. 
StartTime contains the the server startup time. 
VendorInfo contains the vendor information string for the server. 
Version contains the version of the dOPC component. 
This is WrongServertype, a member of class TdOPCSvr. 
What do you think about this topic? Send feedback!
Copyright © 2001-2014 Kassl GmbH ( All rights reserved.