Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 6

Chapter 20 - Project EvtSubscriber

Project Structure

EvtSubscriber.dpr
library EvtSubscriber;

uses
  ComServ,
  EvtSubscriber_TLB in 'EvtSubscriber_TLB.pas',
  MdComEvents_TLB in 'MdComEvents_TLB.pas',
  Subscriber in 'Subscriber.pas' {InformSubscriber: CoClass};

exports
  DllGetClassObject,
  DllCanUnloadNow,
  DllRegisterServer,
  DllUnregisterServer;

{$R *.TLB}

{$R *.RES}

begin
end.
EvtSubscriber_TLB.pas
unit EvtSubscriber_TLB;

// ************************************************************************ //
// WARNING                                                                    
// -------                                                                    
// The types declared in this file were generated from data read from a       
// Type Library. If this type library is explicitly or indirectly (via        
// another type library referring to this type library) re-imported, or the   
// 'Refresh' command of the Type Library Editor activated while editing the   
// Type Library, the contents of this file will be regenerated and all        
// manual modifications will be lost.                                         
// ************************************************************************ //

// PASTLWTR : $Revision:   1.118  $
// File generated on 4/28/2001 4:54:54 PM from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\md6code\20\MdComEvents\EvtSubscriber.tlb (1)
// LIBID: {CC4759F2-5BFD-4D5F-8B73-F251070EDADE}
// LCID: 0
// Helpfile: 
// DepndLst: 
//   (1) v2.0 stdole, (C:\WINDOWS\System32\stdole2.tlb)
//   (2) v4.0 StdVCL, (C:\WINDOWS\system32\stdvcl40.dll)
//   (3) v1.0 MdComEvents, (C:\md6code\20\MdComEvents\MdComEvents.dll)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}

interface

uses ActiveX, Classes, Graphics, MdComEvents_TLB, StdVcl, Variants, Windows;



  // *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:        
//   Type Libraries     : LIBID_xxxx                                      
//   CoClasses          : CLASS_xxxx                                      
//   DISPInterfaces     : DIID_xxxx                                       
//   Non-DISP interfaces: IID_xxxx                                        
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  EvtSubscriberMajorVersion = 1;
  EvtSubscriberMinorVersion = 0;

  LIBID_EvtSubscriber: TGUID = '{CC4759F2-5BFD-4D5F-8B73-F251070EDADE}';

  CLASS_InformSubscriber: TGUID = '{30C23917-52CC-4581-9341-81D2430B39C3}';
type

// *********************************************************************//
// Declaration of CoClasses defined in Type Library                       
// (NOTE: Here we map each CoClass to its Default Interface)              
// *********************************************************************//
  InformSubscriber = IMdInform;


// *********************************************************************//
// The Class CoInformSubscriber provides a Create and CreateRemote method to          
// create instances of the default interface IMdInform exposed by              
// the CoClass InformSubscriber. The functions are intended to be used by             
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.                                            
// *********************************************************************//
  CoInformSubscriber = class
    class function Create: IMdInform;
    class function CreateRemote(const MachineName: string): IMdInform;
  end;

implementation

uses ComObj;

class function CoInformSubscriber.Create: IMdInform;
begin
  Result := CreateComObject(CLASS_InformSubscriber) as IMdInform;
end;

class function CoInformSubscriber.CreateRemote(const MachineName: string): IMdInform;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_InformSubscriber) as IMdInform;
end;

end.
MdComEvents_TLB.pas
unit MdComEvents_TLB;

// ************************************************************************ //
// WARNING                                                                    
// -------                                                                    
// The types declared in this file were generated from data read from a       
// Type Library. If this type library is explicitly or indirectly (via        
// another type library referring to this type library) re-imported, or the   
// 'Refresh' command of the Type Library Editor activated while editing the   
// Type Library, the contents of this file will be regenerated and all        
// manual modifications will be lost.                                         
// ************************************************************************ //

// PASTLWTR : $Revision:   1.118  $
// File generated on 4/28/2001 4:54:54 PM from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\md6code\20\MdComEvents\MdComEvents.dll (2)
// LIBID: {F4A80A55-914B-49EF-93B1-B42EE5E37711}
// LCID: 0
// Helpfile: 
// DepndLst: 
//   (1) v2.0 stdole, (C:\WINDOWS\System32\stdole2.tlb)
// Parent TypeLibrary:
//   (0) v1.0 EvtSubscriber, (C:\md6code\20\MdComEvents\EvtSubscriber.tlb)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}

interface

uses ActiveX, Classes, Graphics, StdVcl, Variants, Windows;


  // *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:        
//   Type Libraries     : LIBID_xxxx                                      
//   CoClasses          : CLASS_xxxx                                      
//   DISPInterfaces     : DIID_xxxx                                       
//   Non-DISP interfaces: IID_xxxx                                        
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  MdComEventsMajorVersion = 1;
  MdComEventsMinorVersion = 0;

  LIBID_MdComEvents: TGUID = '{F4A80A55-914B-49EF-93B1-B42EE5E37711}';

  IID_IMdInform: TGUID = '{202D2CC8-8E6C-4E96-9C14-1FAAE3920ECC}';
  CLASS_MdInform: TGUID = '{0C7A44A5-CC67-4B97-9051-BFE92328EB6B}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                    
// *********************************************************************//
  IMdInform = interface;
  IMdInformDisp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library                       
// (NOTE: Here we map each CoClass to its Default Interface)              
// *********************************************************************//
  MdInform = IMdInform;


// *********************************************************************//
// Interface: IMdInform
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {202D2CC8-8E6C-4E96-9C14-1FAAE3920ECC}
// *********************************************************************//
  IMdInform = interface(IDispatch)
    ['{202D2CC8-8E6C-4E96-9C14-1FAAE3920ECC}']
    procedure Informs(Code: Integer; const Message: WideString); safecall;
  end;

// *********************************************************************//
// DispIntf:  IMdInformDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {202D2CC8-8E6C-4E96-9C14-1FAAE3920ECC}
// *********************************************************************//
  IMdInformDisp = dispinterface
    ['{202D2CC8-8E6C-4E96-9C14-1FAAE3920ECC}']
    procedure Informs(Code: Integer; const Message: WideString); dispid 1;
  end;

// *********************************************************************//
// The Class CoMdInform provides a Create and CreateRemote method to          
// create instances of the default interface IMdInform exposed by              
// the CoClass MdInform. The functions are intended to be used by             
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.                                            
// *********************************************************************//
  CoMdInform = class
    class function Create: IMdInform;
    class function CreateRemote(const MachineName: string): IMdInform;
  end;

implementation

uses ComObj;

class function CoMdInform.Create: IMdInform;
begin
  Result := CreateComObject(CLASS_MdInform) as IMdInform;
end;

class function CoMdInform.CreateRemote(const MachineName: string): IMdInform;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_MdInform) as IMdInform;
end;

end.
Subscriber.pas
unit Subscriber;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  ComObj, ActiveX, EvtSubscriber_TLB, StdVcl, MdComEvents_TLB;

type
  TInformSubscriber = class(TAutoObject, IMdInform)
  protected
    procedure Informs(Code: Integer; const Message: WideString); safecall;
  end;

implementation

uses ComServ, Dialogs, SysUtils;

procedure TInformSubscriber.Informs(Code: Integer;
  const Message: WideString);
begin
  ShowMessage ('Message <' + IntToStr (Code) + '>: ' + Message);
end;

initialization
  TAutoObjectFactory.Create(ComServer, TInformSubscriber, Class_InformSubscriber,
    ciMultiInstance, tmApartment);
end.