各位大虾帮帮忙,帮我看看delphi如何调用pb作的com+组件?张鸿林请进 ( 积分: 200 )

  • 主题发起人 主题发起人 query1
  • 开始时间 开始时间
Q

query1

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾帮帮忙,帮我看看delphi如何调用pb作的com+组件?因为com+组件是其它公司提供的,一时也不知道怎么调用?
project/import type library/Add
Create Unit
Delphi生成一个_tlb.pas文件
在单元中uses可以看到
但是调用过程的时候,服务器连接失败!
不知道如何解决!
email:query1@sina.com
qq:8982628
 
各位大虾帮帮忙,帮我看看delphi如何调用pb作的com+组件?因为com+组件是其它公司提供的,一时也不知道怎么调用?
project/import type library/Add
Create Unit
Delphi生成一个_tlb.pas文件
在单元中uses可以看到
但是调用过程的时候,服务器连接失败!
不知道如何解决!
email:query1@sina.com
qq:8982628
 
创建对象时"服务器连接失败"吗?
你如何创建的?
 
张大侠你好:我是象控件一样使用,不知道这样可以吗;然后调用控件的一个
过程,其中一个过程是procedure aaaa(const:str_in:widestring;var str_out:widestring);
我是这样用的;
procedure TForm1.Button1Click(Sender: TObject);
var str_in:widestring,str_out:widestring;
begin
str_in:='1112';
com组件1.aaaa(str_in, str_out);
//这时候报错!
edit1.text:=str_out;
end;

请赐教!
 
另外在安装组件的时候报错:Error registering COM+ Application.
Ccontact your support personnel for more information.
不知道是出了什么问题?
qq:8982628 email:query1@sina.com
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CmAdmCtl, OleServer, demo_TLB, ComObj;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
AppExec : In_demo;
//In_demo = interface(IDispatch)
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var astr_into,astr_return:widestring;
begin

try
//AppExec :=demo_TLB.CoCOClass_n_demo.CreateRemote('192.168.1.22');
AppExec :=demo_TLB.CoCOClass_n_demo.Create;
//报错
except
ON E:Exceptiondo
raise ERangeError.Create(E.Message);
end;

astr_into:='123';
appexec.uf_pastring(astr_into,astr_return);
edit1.Text:=astr_return;
end;

end.
 
unit demo_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, OleServer, 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
demoMajorVersion = 1;
demoMinorVersion = 0;
LIBID_demo: TGUID = '{1536FF74-3671-4018-BA08-0AEED4D1F4A8}';
IID_In_demo: TGUID = '{A5622066-FCF4-46FD-91E8-F5A468E60F50}';
CLASS_COClass_n_demo: TGUID = '{1C1C1547-8D27-46CF-BA31-950FCE73B02C}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
In_demo = interface;
In_demoDisp = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
COClass_n_demo = In_demo;

// *********************************************************************//
// Interface: In_demo
// Flags: (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID: {A5622066-FCF4-46FD-91E8-F5A468E60F50}
// *********************************************************************//
In_demo = interface(IDispatch)
['{A5622066-FCF4-46FD-91E8-F5A468E60F50}']
procedure uf_pastring(const astr_into: WideString;
var astr_return: WideString);
safecall;
end;

In_demoDisp = dispinterface
['{A5622066-FCF4-46FD-91E8-F5A468E60F50}']
procedure uf_pastring(const astr_into: WideString;
var astr_return: WideString);
dispid 1;
end;

CoCOClass_n_demo = class
class function Create: In_demo;
class function CreateRemote(const MachineName: string): In_demo;
end;

// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TCOClass_n_demo
// Help String : PowerBuilder 8.0.4 generated object
// Default Interface: In_demo
// Def. Intf. DISP? : No
// Event Interface:
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TCOClass_n_demoProperties= class;
{$ENDIF}
TCOClass_n_demo = class(TOleServer)
private
FIntf: In_demo;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TCOClass_n_demoProperties;
function GetServerProperties: TCOClass_n_demoProperties;
{$ENDIF}
function GetDefaultInterface: In_demo;
protected
procedure InitServerData;
override;
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
procedure Connect;
override;
procedure ConnectTo(svrIntf: In_demo);
procedure Disconnect;
override;
procedure uf_pastring(const astr_into: WideString;
var astr_return: WideString);
property DefaultInterface: In_demo read GetDefaultInterface;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TCOClass_n_demoProperties read GetServerProperties;
{$ENDIF}
end;

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

procedure Register;
resourcestring
dtlServerPage = 'ActiveX';
dtlOcxPage = 'ActiveX';
implementation
uses ComObj;
class function CoCOClass_n_demo.Create: In_demo;
begin
Result := CreateComObject(CLASS_COClass_n_demo) as In_demo;
end;

class function CoCOClass_n_demo.CreateRemote(const MachineName: string): In_demo;
begin
Result := CreateRemoteComObject(MachineName, CLASS_COClass_n_demo) as In_demo;
end;

procedure TCOClass_n_demo.InitServerData;
const
CServerData: TServerData = (
ClassID: '{1C1C1547-8D27-46CF-BA31-950FCE73B02C}';
IntfIID: '{A5622066-FCF4-46FD-91E8-F5A468E60F50}';
EventIID: '';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;

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

procedure TCOClass_n_demo.ConnectTo(svrIntf: In_demo);
begin
Disconnect;
FIntf := svrIntf;
end;

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

function TCOClass_n_demo.GetDefaultInterface: In_demo;
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 TCOClass_n_demo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TCOClass_n_demoProperties.Create(Self);
{$ENDIF}
end;

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

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TCOClass_n_demo.GetServerProperties: TCOClass_n_demoProperties;
begin
Result := FProps;
end;
{$ENDIF}
procedure TCOClass_n_demo.uf_pastring(const astr_into: WideString;
var astr_return: WideString);
begin
DefaultInterface.uf_pastring(astr_into, astr_return);
end;

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

function TCOClass_n_demoProperties.GetDefaultInterface: In_demo;
begin
Result := FServer.DefaultInterface;
end;

{$ENDIF}
procedure Register;
begin
RegisterComponents(dtlServerPage, [TCOClass_n_demo]);
end;

end.
 
1.组件一般是通过XXX_Tlb.pas中的
coXXX.Create 或coXXX.CreateRemote创建的
2.
另外在安装组件的时候报错:Error registering COM+ Application.
Ccontact your support personnel for more information.
================
大概是需要一些运行支持库吧,如果你知道这个组件是什么语言开发的,把这个语言的运行支持库拷贝到system32下面
比如,我用delphi开发的组件,一般都会build run time package,就需要*.bpl的支持
3.一般来说,调用别人的服务,最好获得他们的文档,有些参数类型,没有文档,我们是无法
知道如何解释的,当然,你到现在为止,还没遇到这个问题
 
大侠你在,太好了!
您看我的代码有错误吗?
 
这个我可不熟悉,抱歉
 
TO:app2001
没关系,同样感谢!
 
to 张鸿林:
兄弟们都公认你对com+拽!你怕要考虑开个源代码给大家看看呢!
 
确实看不出你的代码有什么不对的地方(我回上贴时还没有看到你的代码)
要不,留个qq,发给我测试一下?
to,
13708782004,不敢!
 
我的qq:8982628
email:query1@sina.com
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
I
回复
0
查看
741
import
I
后退
顶部