关于COM+ Event Object的问题?(100分)

  • 主题发起人 主题发起人 goodbegin
  • 开始时间 开始时间
G

goodbegin

Unregistered / Unconfirmed
GUEST, unregistred user!
我想通过DELPHI6做DLL,可以使其他的开发工具调用本DLL的内容。我的步骤是这样的:
一、新建Active Library(TestProject)
二、新建Com+ Event Object(Test)
三、添加属性,例如(Name)
四、在Test单元文件中建立Get_Name函数和Set_Name过程
5、编译通过

现在用DELPHI6的Import Active Library
有Test1:TTest
我给Test1.Name赋值,例如 Test1.Name:='1232'
就提示abstractError

 
Com+ Event Object???
不知道等价的原生com+定义是什么,如果是一个事件component,没听说能够定义属性。
 
function Get_Name: WideString
virtual
safecall
abstract;//注意abstract声明为抽象方法
procedure Set_Name(const Value: WideString)
virtual
safecall
abstract;;//注意abstract声明为抽象方法
Get_Name函数和Set_Name过程均为抽象的方法,必须在子类实现。否则报abstractError
 
我的原文是这样的:
文件:Transfer_TLB
unit Transfer_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 2002-11-19 17:04:02 from Type Library described below.

// ************************************************************************ //
// Type Lib: D:/Êý¾Ý´«Êä/ActiveDLL/Transfer.tlb (1)
// LIBID: {4B2A10E6-42AB-4AB4-B065-A08303DC7175}
// LCID: 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.
{$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
TransferMajorVersion = 1;
TransferMinorVersion = 0;

LIBID_Transfer: TGUID = '{4B2A10E6-42AB-4AB4-B065-A08303DC7175}';

IID_ISend: TGUID = '{DDFEA5A3-FE37-424E-B17C-40151289EFDB}';
CLASS_Send: TGUID = '{6F20EC19-BB54-4A6D-86E1-AA50C0FC729F}';
IID_IReceive: TGUID = '{D0D713D9-F492-4697-BC9B-B0AACA72784B}';
CLASS_Receive: TGUID = '{1B45CC58-CFA0-4584-A941-2A2C0D5B96C0}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
ISend = interface;
ISendDisp = dispinterface;
IReceive = interface;
IReceiveDisp = dispinterface;

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


// *********************************************************************//
// Interface: ISend
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {DDFEA5A3-FE37-424E-B17C-40151289EFDB}
// *********************************************************************//
ISend = interface(IDispatch)
['{DDFEA5A3-FE37-424E-B17C-40151289EFDB}']
function Get_RemoteHost: WideString
safecall;
procedure Set_RemoteHost(const Value: WideString)
safecall;
function Get_Port: Integer
safecall;
procedure Set_Port(Value: Integer)
safecall;
function Get_SendFileName: WideString
safecall;
procedure Set_SendFileName(const Value: WideString)
safecall;
function Get_State: Integer
safecall;
function Get_FileLenght: Integer
safecall;
procedure Set_FileLenght(Value: Integer)
safecall;
function Get_ErrorNumber: Integer
safecall;
function Get_ErrorDescription: WideString
safecall;
procedure Send
safecall;
property RemoteHost: WideString read Get_RemoteHost write Set_RemoteHost;
property Port: Integer read Get_Port write Set_Port;
property SendFileName: WideString read Get_SendFileName write Set_SendFileName;
property State: Integer read Get_State;
property FileLenght: Integer read Get_FileLenght write Set_FileLenght;
property ErrorNumber: Integer read Get_ErrorNumber;
property ErrorDescription: WideString read Get_ErrorDescription;
end;

// *********************************************************************//
// DispIntf: ISendDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {DDFEA5A3-FE37-424E-B17C-40151289EFDB}
// *********************************************************************//
ISendDisp = dispinterface
['{DDFEA5A3-FE37-424E-B17C-40151289EFDB}']
property RemoteHost: WideString dispid 1;
property Port: Integer dispid 2;
property SendFileName: WideString dispid 3;
property State: Integer readonly dispid 4;
property FileLenght: Integer dispid 5;
property ErrorNumber: Integer readonly dispid 6;
property ErrorDescription: WideString readonly dispid 7;
procedure Send
dispid 8;
end;

// *********************************************************************//
// Interface: IReceive
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {D0D713D9-F492-4697-BC9B-B0AACA72784B}
// *********************************************************************//
IReceive = interface(IDispatch)
['{D0D713D9-F492-4697-BC9B-B0AACA72784B}']
function Get_Port: Integer
safecall;
procedure Set_Port(Value: Integer)
safecall;
function Get_SourceFileName: WideString
safecall;
function Get_SaveFileName: WideString
safecall;
procedure Set_SaveFileName(const Value: WideString)
safecall;
function Get_FileLenght: Integer
safecall;
function Get_State: Integer
safecall;
function Get_ErrorNumber: Integer
safecall;
function Get_ErrorDescription: WideString
safecall;
property Port: Integer read Get_Port write Set_Port;
property SourceFileName: WideString read Get_SourceFileName;
property SaveFileName: WideString read Get_SaveFileName write Set_SaveFileName;
property FileLenght: Integer read Get_FileLenght;
property State: Integer read Get_State;
property ErrorNumber: Integer read Get_ErrorNumber;
property ErrorDescription: WideString read Get_ErrorDescription;
end;

// *********************************************************************//
// DispIntf: IReceiveDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {D0D713D9-F492-4697-BC9B-B0AACA72784B}
// *********************************************************************//
IReceiveDisp = dispinterface
['{D0D713D9-F492-4697-BC9B-B0AACA72784B}']
property Port: Integer dispid 1;
property SourceFileName: WideString readonly dispid 2;
property SaveFileName: WideString dispid 3;
property FileLenght: Integer readonly dispid 4;
property State: Integer readonly dispid 5;
property ErrorNumber: Integer readonly dispid 6;
property ErrorDescription: WideString readonly dispid 7;
end;

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

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

implementation

uses ComObj;

class function CoSend.Create: ISend;
begin
Result := CreateComObject(CLASS_Send) as ISend;
end;

class function CoSend.CreateRemote(const MachineName: string): ISend;
begin
Result := CreateRemoteComObject(MachineName, CLASS_Send) as ISend;
end;

class function CoReceive.Create: IReceive;
begin
Result := CreateComObject(CLASS_Receive) as IReceive;
end;

class function CoReceive.CreateRemote(const MachineName: string): IReceive;
begin
Result := CreateRemoteComObject(MachineName, CLASS_Receive) as IReceive;
end;

end.

文件:Send
unit Send;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
ComObj, ActiveX, Transfer_TLB, StdVcl;

type
TSend = class(TAutoObject, ISend)

protected
function Get_RemoteHost: WideString
virtual
safecall
abstract;
procedure Set_RemoteHost(const Value: WideString)
virtual
safecall
abstract;
function Get_Port: Integer
virtual
safecall
abstract;
function Get_SendFileName: WideString
virtual
safecall
abstract;
procedure Set_Port(Value: Integer)
virtual
safecall
abstract;
procedure Set_SendFileName(const Value: WideString)
virtual
safecall
abstract;
function Get_FileLenght: Integer
virtual
safecall
abstract;
function Get_State: Integer
virtual
safecall
abstract;
procedure Set_FileLenght(Value: Integer)
virtual
safecall
abstract;
procedure Set_State(Value: Integer)
virtual
safecall
abstract;
function Get_ErrorDescription: WideString
virtual
safecall
abstract;
function Get_ErrorNumber: Integer
virtual
safecall
abstract;
procedure Send
virtual
safecall
abstract;
{ Protected declarations }
end;

var
RemoteHost:WideString;
Port:Longint;
SendFileName:WideString;
FileLenght:Longint;
State:Integer;
ErrorNumber:Integer;
ErrorDescription:WideString;

implementation

uses ComServ;

function Get_RemoteHost:WideString;
begin
Result:= RemoteHost;
end;

procedure Set_RemoteHost(const Value:WideString);
begin
RemoteHost:=Value;
end;

function Get_Port:Longint;
begin
Result:=Port;
end;

procedure Set_Port(const Value:Integer);
begin
Port:=Value;
end;

function Get_SendFileName:WideString;
begin
Result:=SendFileName;
end;

procedure Set_SendFileName(const Value:WideString);
begin
SendFileName:=Value;
end;

function Get_FileLenght:Longint;
begin
Result:=FileLenght;
end;

procedure Set_FileLenght(const Value:integer);
begin
FileLenght:=Value;
end;

function Get_State:Longint;
begin
Result:=State;
end;

procedure Set_State(const Value:integer);
begin
State:=Value;
end;

function Get_ErrorNumber:Integer;
begin
Result:=ErrorNumber;
end;

function Get_ErrorDescription:widestring;
begin
Result:=ErrorDescription;
end;

initialization
TAutoObjectFactory.Create(ComServer, TSend, Class_Send,
ciMultiInstance, tmApartment);
end.


在调用程序中声明Send1:TSEND,写语句
Send1.RemoteHost:='adsfd'
执行时报第一贴的错误
 
粗略看了一下,发现你的实现单元的函数什么有问题,解决方法很简单例如:
function Get_FileLenght: Integer
virtual
safecall
abstract;//你的声明
function Get_FileLenght: Integer
virtual
safecall;//改动后
即只要吧abstract指示字去掉就行了
 
感谢朋友的支持!![:D]
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
601
import
I
后退
顶部