This document, and the ZIP archive of which it is part, are intended to help give a brief introduction to OLE for Process Control (OPC) client programming using Embarcadero (formerly Borland) Delphi.
The ZIP file contains Delphi source code for a simple OPC client application.
You will also need the Delphi conversion of the OPC custom interfaces, available separately from the Delphi page at OPC Programmers' Connection.
The code has been confirmed to be compatible with with Delphi 5 to 7, and Delphi 2005 to 2010 for Win32.
September 2nd 2009: Minor changes for compatibility with Delphi 2010.
September 28th 2008: Minor changes for compatibility with Delphi 2009 for Win32.
January 2nd 2006: Minor changes for compatibility with Delphi 2006 for Win32.
November 28th 2004: Minor changes for compatibility with Delphi 2005 for Win32.
September 3rd 2002: Minor changes for compatibility with Delphi 7.0.
July 12th 2001: ServerAddGroup function in OPCutils.pas modified to take the client handle for the group as a parameter.
July 5th 2001: Now compatible with Delphi 6 (new Variants unit conditionally added to uses lists as required).
March 7th 2001: Minor changes to reflect modified Pascal definition for the IOPCDataCallback interface, and the need to use the new OPCtypes.pas unit.
June 8th 2000: Added wrapper function (and call to it) for IOPCSyncIO.Write.
February 21st 2000: Updated to make use of connection point system for data callbacks, as well as the older IDataObject/IAdviseSink mechanism.
January 24th 2000: Client program updated to use modified Simulation Server from Matrikon.
October 12th 1999: OPC interface files and sample client program now packaged separately.
September 11th 1999: Now works with Delphi 3, 4 and 5. Added CoInitializeSecurity call to prevent blocking of advise callbacks with certain configurations of DCOM.
June 22nd 1999: Original version, compatible with Delphi 4.
Inside the ZIP archive you will find the following files.
| OPCquick.* | Main application files | |
| OPCutils.pas | Miscellaneous utility functions | |
| readme-client.htm | This file |
The Pascal source code for the sample application is in OPCquick.dpr.
The custom OPC interfaces have been used throughout. This leads to greater runtime efficiency, easier system configuration, and maximum code reusability. As supplied, the client program connects to a sample OPC server from MatrikonOPC (http://www.matrikonopc.com/), but it is a trivial matter to change this.
So as to be as small as possible, the client program is a console application. However, it uses a number of the key OPC methods, including synchronous reading and writing, and asynchronous notifications via an advise sink.
Non-Delphi programmers should find the code very readable. Note the use of the keyword as; this is a simple and elegant way of performing a QueryInterface (as is used elsewhere in Object Pascal for dynamic typecasting). Note also the absence of calls to AddRef and Release: COM reference counting is handled automatically by Delphi.
Some of the work of porting the OPC interfaces to Delphi was performed initially while working at Eurotherm Limited. Their cooperation in allowing this code to be published is gratefully acknowledged. The iTools suite of applications from Eurotherm includes several OPC client programs developed using Delphi.
Thanks are also due to the many Delphi OPC developers who have contributed ideas, suggestions, and corrections.
Although every effort has been made to faithfully convert the original C and IDL declarations to Object Pascal, and the results have been used and tested extensively, I can't of course actually guarantee their correctness. Neither will I be held responsible for any loss or damage arising from their use.
I would be grateful to know of any problems with these files.
Mike Dillamore
OPC Programmers' Connection
http://www.opcconnect.com/
mailto:opc@opcconnect.com
September 2nd 2009