Delphi 封装(4)-物理上的封装-物理封装和动态链接

本文介绍了一个使用 Delphi 进行 COM+ 对象封装的具体示例,包括了单元文件的内容、类型库信息及接口定义。该示例展示了如何通过 IDemoComObj 接口实现 drive 和 ride 方法,并提供了创建 DemoComObj CoClass 的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

unit DemoSvr_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 : 1.2
// File generated on 03-4-9 21:09:18 from Type Library described below.

// ************************************************************************  //
// Type Lib: E:\Delphi面向对象编程思想\示例程序\封装\用COM+封装对象\DemoSvr.tlb (1)
// LIBID: {B96FFC20-65BC-11D7-B847-001060806215}
// LCID: 0
// Helpfile: 
// HelpString: DemoSvr Library
// DepndLst: 
//   (1) v2.0 stdole, (C:\WINDOWS\SYSTEM\stdole2.tlb)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
interface

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

// *********************************************************************//
// 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
  DemoSvrMajorVersion = 1;
  DemoSvrMinorVersion = 0;

  LIBID_DemoSvr: TGUID = '{B96FFC20-65BC-11D7-B847-001060806215}';

  IID_IDemoComObj: TGUID = '{B96FFC21-65BC-11D7-B847-001060806215}';
  CLASS_DemoComObj: TGUID = '{B96FFC23-65BC-11D7-B847-001060806215}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                    
// *********************************************************************//
  IDemoComObj = interface;

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


// *********************************************************************//
// Interface: IDemoComObj
// Flags:     (256) OleAutomation
// GUID:      {B96FFC21-65BC-11D7-B847-001060806215}
// *********************************************************************//
  IDemoComObj = interface(IUnknown)
    ['{B96FFC21-65BC-11D7-B847-001060806215}']
    procedure Drive; stdcall;
    procedure ride; stdcall;
  end;

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

implementation

uses ComObj;

class function CoDemoComObj.Create: IDemoComObj;
begin
  Result := CreateComObject(CLASS_DemoComObj) as IDemoComObj;
end;

class function CoDemoComObj.CreateRemote(const MachineName: string): IDemoComObj;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_DemoComObj) as IDemoComObj;
end;

end.

class function CoDemoComObj.Create: IDemoComObj;
begin
  Result := CreateComObject(CLASS_DemoComObj) as IDemoComObj;
end;

function CreateComObject(const ClassID: TGUID): IUnknown;
begin
  OleCheck(CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or
    CLSCTX_LOCAL_SERVER, IUnknown, Result));
end;

class function CoDemoComObj.CreateRemote(const MachineName: string): IDemoComObj;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_DemoComObj) as IDemoComObj;
end;

 

转载于:https://www.cnblogs.com/YiShen/p/9869996.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值