Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco


Home: Code Repository: Mastering Delphi 6

Chapter 20 - Project Publisher

Project Structure

Publisher.dpr
program Publisher;

uses
  Forms,
  PublisherForm in 'PublisherForm.pas' {Form1},
  MdComEvents_TLB in 'MdComEvents_TLB.pas';

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
PublisherForm.pas
unit PublisherForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, MdComEvents_TLB;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    Inform: IMdInform;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

  {$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Inform.Informs (20, Edit1.Text);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Inform := CoMdInform.Create;
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.
PublisherForm.dfm
object Form1: TForm1
  Left = 199
  Top = 109
  Width = 383
  Height = 187
  Caption = 'Publisher'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 56
    Top = 56
    Width = 75
    Height = 25
    Caption = 'Informs'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Left = 144
    Top = 56
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'Here am I'
  end
end