home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 March / Chip_1999-03_cd.bin / zkuste / delphi / INFO / DI9806BL.ZIP / Cp / Client / ChatEvent.pas < prev    next >
Pascal/Delphi Source File  |  1998-05-08  |  2KB  |  65 lines

  1. { *****************************************************************************
  2.   Implementing COM Component Callbacks in Delphi
  3.   Code written for Delphi Informant publication
  4.  
  5.   Comments, questions, suggestions?
  6.   Binh Ly, Systems Analyst (bly@brickhouse.com)
  7.   Brickhouse Data Systems (http://www.brickhouse.com)
  8.   *****************************************************************************
  9. }
  10. unit ChatEvent;
  11.  
  12. interface
  13.  
  14. uses
  15.   ChatServer_TLB,
  16.   ComObj,
  17.   Classes
  18.   ;
  19.  
  20. type
  21.   TChatMessageEvent = procedure (const UserName, Message : string) of object;
  22.  
  23.   TChatEvent = class (TAutoIntfObject, IChatEvent)
  24.   protected
  25.     { IChatEvent }
  26.     procedure GotMessage (const UserName, Message: WideString); safecall;
  27.   protected
  28.     FOnMessage : TChatMessageEvent;
  29.   public
  30.     constructor Create;
  31.     property OnMessage : TChatMessageEvent read FOnMessage write FOnMessage;
  32.   end;
  33.  
  34. implementation
  35.  
  36. uses
  37.   Windows,
  38.   ActiveX
  39.   ;
  40.  
  41. { TChatEvent }
  42.  
  43. procedure TChatEvent.GotMessage (const UserName, Message: WideString);
  44. begin
  45.   { IChatEvent.GotMessage callback implementation. we just trigger the
  46.      OnMessage event.
  47.   }
  48.   if Assigned (OnMessage) then
  49.     OnMessage (UserName, Message);
  50. end;
  51.  
  52. constructor TChatEvent.Create;
  53. var
  54.   ifTypeLib : ITypeLib;
  55. begin
  56.   { enable both IDispatch binding using type library } 
  57.   OleCheck (LoadRegTypeLib(LIBID_ChatServer, 1, 0, 0, ifTypeLib));
  58.   inherited Create (ifTypeLib, IChatEvent);
  59.  
  60.   { artificially increment ref count so that we don't get destroyed prematurely }
  61.   _AddRef;
  62. end;
  63.  
  64. end.
  65.