⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dcptypeserver_tlb.pas

📁 详细讲述如何用delphi进行com编程
💻 PAS
字号:
unit DCPTypeServer_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.88  $
// File generated on 8/10/1999 2:45:39 PM from Type Library described below.

// *************************************************************************//
// NOTE:                                                                      
// Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties  
// which return objects that may need to be explicitly created via a function 
// call prior to any access via the property. These items have been disabled  
// in order to prevent accidental use from within the object inspector. You   
// may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively   
// removing them from the $IFDEF blocks. However, such items must still be    
// programmatically created via a method of the appropriate CoClass before    
// they can be used.                                                          
// ************************************************************************ //
// Type Lib: D:\Book\Chap04\TIServer.tlb (1)
// IID\LCID: {91ADB6E6-4F4D-11D3-B84B-0040F67455FE}\0
// Helpfile: 
// DepndLst: 
//   (1) v2.0 stdole, (C:\WINNT\System32\STDOLE2.TLB)
//   (2) v4.0 StdVCL, (C:\WINNT\System32\STDVCL40.DLL)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
interface

uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;

// *********************************************************************//
// 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
  DCPTypeServerMajorVersion = 1;
  DCPTypeServerMinorVersion = 0;

  LIBID_DCPTypeServer: TGUID = '{91ADB6E6-4F4D-11D3-B84B-0040F67455FE}';

  IID_IUnitAuto: TGUID = '{91ADB6E7-4F4D-11D3-B84B-0040F67455FE}';
  CLASS_UnitAuto: TGUID = '{91ADB6E9-4F4D-11D3-B84B-0040F67455FE}';

// *********************************************************************//
// Declaration of Enumerations defined in Type Library                    
// *********************************************************************//
// Constants for enum AreaUnit
type
  AreaUnit = TOleEnum;
const
  auSquareMeters = $00000000;
  auSquareCentimeters = $00000001;
  auSquareYards = $00000002;
  auSquareFeet = $00000003;
  auSquareInches = $00000004;
  auSquareKilometers = $00000005;
  auSquareMiles = $00000006;
  auAcres = $00000007;

type

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

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


// *********************************************************************//
// Interface: IUnitAuto
// Flags:     (256) OleAutomation
// GUID:      {91ADB6E7-4F4D-11D3-B84B-0040F67455FE}
// *********************************************************************//
  IUnitAuto = interface(IUnknown)
    ['{91ADB6E7-4F4D-11D3-B84B-0040F67455FE}']
    function  Convert(Quantity: Double; InUnit: SYSINT; OutUnit: SYSINT): Double; stdcall;
    function  Get_Name: WideString; stdcall;
    procedure Set_Name(const Param1: WideString); stdcall;
  end;

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


// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object    : TUnitAuto
// Help String      : UnitAuto Object
// Default Interface: IUnitAuto
// Def. Intf. DISP? : No
// Event   Interface: 
// TypeFlags        : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  TUnitAutoProperties= class;
{$ENDIF}
  TUnitAuto = class(TOleServer)
  private
    FIntf:        IUnitAuto;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    FProps:       TUnitAutoProperties;
    function      GetServerProperties: TUnitAutoProperties;
{$ENDIF}
    function      GetDefaultInterface: IUnitAuto;
  protected
    procedure InitServerData; override;
    function  Get_Name: WideString;
    procedure Set_Name(const Param1: WideString);
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure Connect; override;
    procedure ConnectTo(svrIntf: IUnitAuto);
    procedure Disconnect; override;
    function  Convert(Quantity: Double; InUnit: SYSINT; OutUnit: SYSINT): Double;
    property  DefaultInterface: IUnitAuto read GetDefaultInterface;
  published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    property Server: TUnitAutoProperties read GetServerProperties;
{$ENDIF}
  end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object    : TUnitAuto
// (This object is used by the IDE's Property Inspector to allow editing
//  of the properties of this server)
// *********************************************************************//
 TUnitAutoProperties = class(TPersistent)
  private
    FServer:    TUnitAuto;
    function    GetDefaultInterface: IUnitAuto;
    constructor Create(AServer: TUnitAuto);
  protected
    function  Get_Name: WideString;
    procedure Set_Name(const Param1: WideString);
  public
    property DefaultInterface: IUnitAuto read GetDefaultInterface;
  published
  end;
{$ENDIF}


procedure Register;

implementation

uses ComObj;

class function CoUnitAuto.Create: IUnitAuto;
begin
  Result := CreateComObject(CLASS_UnitAuto) as IUnitAuto;
end;

class function CoUnitAuto.CreateRemote(const MachineName: string): IUnitAuto;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_UnitAuto) as IUnitAuto;
end;

procedure TUnitAuto.InitServerData;
const
  CServerData: TServerData = (
    ClassID:   '{91ADB6E9-4F4D-11D3-B84B-0040F67455FE}';
    IntfIID:   '{91ADB6E7-4F4D-11D3-B84B-0040F67455FE}';
    EventIID:  '';
    LicenseKey: nil;
    Version: 500);
begin
  ServerData := @CServerData;
end;

procedure TUnitAuto.Connect;
var
  punk: IUnknown;
begin
  if FIntf = nil then
  begin
    punk := GetServer;
    Fintf:= punk as IUnitAuto;
  end;
end;

procedure TUnitAuto.ConnectTo(svrIntf: IUnitAuto);
begin
  Disconnect;
  FIntf := svrIntf;
end;

procedure TUnitAuto.DisConnect;
begin
  if Fintf <> nil then
  begin
    FIntf := nil;
  end;
end;

function TUnitAuto.GetDefaultInterface: IUnitAuto;
begin
  if FIntf = nil then
    Connect;
  Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  Result := FIntf;
end;

constructor TUnitAuto.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  FProps := TUnitAutoProperties.Create(Self);
{$ENDIF}
end;

destructor TUnitAuto.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  FProps.Free;
{$ENDIF}
  inherited Destroy;
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TUnitAuto.GetServerProperties: TUnitAutoProperties;
begin
  Result := FProps;
end;
{$ENDIF}

function  TUnitAuto.Get_Name: WideString;
begin
  Result := DefaultInterface.Get_Name;
end;

procedure TUnitAuto.Set_Name(const Param1: WideString);
begin
  DefaultInterface.Set_Name(Param1);
end;

function  TUnitAuto.Convert(Quantity: Double; InUnit: SYSINT; OutUnit: SYSINT): Double;
begin
  Result := DefaultInterface.Convert(Quantity, InUnit, OutUnit);
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TUnitAutoProperties.Create(AServer: TUnitAuto);
begin
  inherited Create;
  FServer := AServer;
end;

function TUnitAutoProperties.GetDefaultInterface: IUnitAuto;
begin
  Result := FServer.DefaultInterface;
end;

function  TUnitAutoProperties.Get_Name: WideString;
begin
  Result := DefaultInterface.Get_Name;
end;

procedure TUnitAutoProperties.Set_Name(const Param1: WideString);
begin
  DefaultInterface.Set_Name(Param1);
end;

{$ENDIF}

procedure Register;
begin
  RegisterComponents('Servers',[TUnitAuto]);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -