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 19 - Project Propcom

Project Structure

Propcom.dpr
library PropCom;

uses
  ComServ,
  NumIntf in 'NumIntf.pas',
  NumServ in 'NumServ.pas',
  PropCom_TLB in 'PropCom_TLB.pas';

exports
  DllGetClassObject,
  DllCanUnloadNow,
  DllRegisterServer,
  DllUnregisterServer;

{$R *.TLB}

{$R *.RES}

  end.
NumIntf.pas
unit NumIntf;

interface

type
  INumberProp = interface
    ['{B36C5800-8E59-11D0-98D0-444553540000}']
    function GetValue: Integer; stdcall;
    procedure SetValue (New: Integer); stdcall;
    procedure Increase; stdcall;
    property Value: Integer
      read GetValue write SetValue;
  end;

implementation

end.
NumServ.pas
unit NumServ;

interface

uses
  Windows, ActiveX, ComObj, NumIntf;

type
  TNumServer = class(TComObject, INumberProp)
  private
    fValue: Integer;
  public
    function GetValue: Integer; virtual; stdcall;
    procedure SetValue (New: Integer); virtual; stdcall;
    procedure Increase; virtual; stdcall;
    procedure Initialize; override;
    destructor Destroy; override;
  end;

const
  Class_NumPropServer: TGUID =
    '{B165F7A1-DDF9-11D1-B9F1-004845400FAA}';

implementation

uses ComServ;

{ TNumServer }

destructor TNumServer.Destroy;
begin
  inherited;
  MessageBox (0, 'Object Destroyed',
    'TDLLNumber', mb_OK); // API call
end;

function TNumServer.GetValue: Integer;
begin
  Result := fValue;
end;

procedure TNumServer.Increase;
begin
  Inc (fValue);
end;

procedure TNumServer.Initialize;
begin
  inherited;
  fValue := 10;
end;

procedure TNumServer.SetValue(New: Integer);
begin
  fValue := New;
end;

initialization
  TComObjectFactory.Create(ComServer, TNumServer, Class_NumPropServer,
    'NumPropServer', 'Num Prop Server (Prop Com)', ciMultiInstance, tmSingle);
end.
PropCom_TLB.pas
unit PropCom_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.130  $
// File generated on 6/21/2001 5:54:18 PM from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\md6code\19\PropCom\PropCom.tlb (1)
// LIBID: {5B2EF183-3AAE-11D3-B9F1-00000100A27B}
// LCID: 0
// Helpfile: 
// DepndLst: 
//   (1) v2.0 stdole, (C:\WINDOWS\System32\stdole2.tlb)
//   (2) v4.0 StdVCL, (C:\WINDOWS\system32\stdvcl40.dll)
// ************************************************************************ //
{$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
  PropComMajorVersion = 1;
  PropComMinorVersion = 0;

  LIBID_PropCom: TGUID = '{5B2EF183-3AAE-11D3-B9F1-00000100A27B}';


implementation

uses ComObj;

end.