dOPC Client Toolkit Help file
Example

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;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, dOPC, dOPCComn, dOPCIntf;

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

procedure TForm1.bStartClick(Sender: TObject);
var
  G    : TdOPCGroup;
begin
  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
end;

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

See Also

Copyright © 2001-2014 Kassl GmbH (http://www.kassl.de). All rights reserved.