关于visibrokerfordelphi的使用

上传人:xiao****1972 文档编号:84141342 上传时间:2019-03-02 格式:DOC 页数:32 大小:97KB
返回 下载 相关 举报
关于visibrokerfordelphi的使用_第1页
第1页 / 共32页
关于visibrokerfordelphi的使用_第2页
第2页 / 共32页
关于visibrokerfordelphi的使用_第3页
第3页 / 共32页
关于visibrokerfordelphi的使用_第4页
第4页 / 共32页
关于visibrokerfordelphi的使用_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《关于visibrokerfordelphi的使用》由会员分享,可在线阅读,更多相关《关于visibrokerfordelphi的使用(32页珍藏版)》请在金锄头文库上搜索。

1、关于VisiBroker For Delphi的使用(3)-CORBA技术实践(一)email: 3,数组对象与简单数据对象的传递前面提到了一些较为简单的数据操作,我们都可以想象一下,如果操作CORBA对象与操作C/S结构的数据对象一样的方便,那么CORBA又有什么神奇了,不知道看过李维的分布式多层应用系统的书籍时,是否留意到李维对CORBA的评价,无论你看过还是没有看过,我都要告诉正在使用CORBA编程的朋友们,CORBA比COM/COM+简单,而CORBA的跨平台特性,以及与COM/COM+同样的负载平衡能力,足以让我们将这项分布式技术应用到应用体系的设计之中,其实对于使用Borland的

2、产品开发分布式系统无论你采用CORBA或是COM/COM+其实最核心的技术就是MIDAS,因为你总可以在CORBA/COM/COM+中看到MIDAS的影子,所以我建议无论你是准备学习CORBA还是学习COM/COM+最好先学习一下MIDAS,本文不涉及MIDAS,关于MIDAS请看李维的Delphi5.X分布式多层应用系统篇。为什么我从开始就一直要大家使用文本编辑器之类的东西书写IDL,而不用TypeLibrary来书写IDL,其实我觉得只是为了让刚刚接触CORBA的程序员获得一些更多的IDL方面的知识罢了,在实际的开发中你可以完全很方便的使用TypeLibrary来编写接口规则。下面我简要的

3、列举几类IDL书写的事例与利用IDL2PAS生成的PASCAL代码。1、)常量的定义/*IDL书写*/module MyCRB const long iMyConst=1; interface myFace const long iiMyConst=2;/*Pascal*/unit MyCRB_I;interfaceuses Corba;const iMyCOnst:integer=1; myFace_iiMyConst=2;2、)不在接口中申明的常量/*IDL*/module MyCRB const long myconst=1;/*pascal*/unit MyCRB_I;interfac

4、econst myconst:integer=1;3、)枚举类型/*IDL*/enum MyCRBKindA,B,C,D,./*pascal*/myCRBkind=(A,B,C,D.);4、)结构体/*IDL*/struct mystructtype long X;string Y;boolean Z;/*pascal*/XXX_I.pastype mystructtype=interface;/XXX_C.pasmystructtype=interfacefunction _get_X:integer;function _get_Y:string;function _get_Z:boolea

5、n;procedure _set_X(const Value:integer); procedure _set_Y(const Value:string); procedure _set_Z(const Value:boolean); property X:integer read _get_X write _Set_X;property Y:string read _get_Y write _Set_Y;property Z:boolean read _get_Z write _Set_Z;.还有太多的代码,自己创建一个看一下,为了节约篇幅我就不做详细的翻译了下面请大家试一下以下的申明会生成

6、什么样的Pascal代码5、)联合体union un_exp switch(long) case 1:long x; case 2:string y;case 3:st_exp Z;6、sequence(我理解为动态数组)typedef sequence UnboundeSeq;typedef sequence ShortBoundSeq7, 数组 const long ArrayBound=10;typedef long longArrayArrayBound;8, 抽象接口module exp interface myfacelong op(in string s);9,多重继承 modu

7、le Minterface A void A1(); void A2(); ;interface B void B1(); void B2();interface AB:B,Avoid AB1()void AB2();10,交叉模型定义module m1interface if1;module m2 interface if2m1:if1 getIf1();interface if1m2:if2 getif2();以上我介绍了一些数据的定义规范,然而我们需要不仅仅是这样的一些比较抽象的接口定义法则,我们要将法则应用到实际的开发中去,那么我们又是如何运用这些法则了,对于接口描述语言的翻译我前面讲

8、到直接使用IDL2PAS就不讲了,以后的章节中也不会在去将如何转换的问题。下面我们实践一下:编写接口定义一个返回为浮点类型,输入为短整型变量数组对象的方法typedef short ArrayType3;/自定义类型定义长度为3的数组interface Account float InputArray(in ArrayType myArray);/输入为整形数组,返回类型为float的方法;/服务端程序的处理xxx_impl.pasinterfaceuses SysUtils, CORBA, account_i, account_c;type TAccount = class; TAccoun

9、t = class(TInterfacedObject, account_i.Account) protected /* public constructor Create; function InputArray ( const myArray : account_i.ArrayType): Single; end;implementationuses ServerMain;constructor TAccount.Create;begin inherited;end;function TAccount. InputArray (const myArray : account_i.Array

10、Type): Single;var j: Integer;begin/ account_i.ArrayType是指我们自定义的数组类型在account_I单元中 for j := 0 to 2 do beginForm1.Memo1.Lines.Add(myArray + IntToStr(j) + = + IntToStr(myArrayj) );/接受从客户端传递过来的数组变量并将其依次加入到主窗体的MEMO中 end; result := random * 100;/返回一个随机数end;initialization randomize;end./服务端程序主单元unit ServerM

11、ain;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Corba, Account_I, Account_C, Account_S, Account_Impl, StdCtrls;type TForm1 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private private declarations protected protected declarations Acc

12、t : Account; / skeleton 对象 procedure InitCorba; public public declarations end;var Form1: TForm1;implementation$R *.dfmprocedure TForm1.InitCorba;begin CorbaInitialize; / Add CORBA server Code Here Acct := TAccountSkeleton.Create(Array Server, TAccount.Create); BOA.ObjIsReady(Acct as _Object);end;pr

13、ocedure TForm1.FormCreate(Sender: TObject);begin InitCorba; Memo1.Lines.Add(Account object created.); Memo1.Lines.Add(Server is ready);end;end./客户端程序unit ClientMain;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Corba, StdCtrls, Account_I, Account_C;type TFor

14、m1 = class(TForm) Button1: TButton; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private private declarations protected protected declarations Acct : Account; myArray : ArrayType; procedure InitCorba; public public declarations end;var Form1: TForm1;impl

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号