unit fmMain;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure AppMsg(const sMsg : String);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  Class_MyCOM: TGUID = '{2D80D5A3-01FC-4E30-B7DB-74F7301CE7C9}';

procedure TForm1.AppMsg(const sMsg: String);
begin
  ListBox1.Items.Add(sMsg);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  aIntf : IUnknown;
  iCount : Integer;
begin
  CoInitialize(nil);
  try
    OleCheck(CoCreateInstance(Class_MyCOM, nil, CLSCTX_INPROC_SERVER or
    CLSCTX_LOCAL_SERVER, IUnknown, aIntf));
    iCount := aIntf._AddRef;
    AppMsg(IntToStr(iCount));
    aIntf._Release;
  finally
    aIntf._Release;
    CoUninitialize;
  end;
end;

end.
