;
现在按照我们上一届讲的生成框架代码,接下来我们在Crb_impl中加入
Result := StrToInt(Form1.Edit1.Text);
加在那儿呢加在Getany方法中哪,如下
function TTestAny.GetAny : ANY;
begin
Result := StrToInt(Form1.Edit1.Text);
end;
这个接口的意义是将我们的服务程序的主窗体上的Edit1上的字符串返回给接口,以便于客户程序从接口获得该字符数据。
当然必须在我们的主窗体上作如下声明
unit ServerMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Corba,
CRB_I, CRB_C, CRB_S, CRB_Impl, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ private declarations }
protected
MyAnyTest :TTestAny; // 主干对象
procedure InitCorba;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.InitCorba;
begin
CorbaInitialize;
//加入CRB服务代码
MyAnyTest := TTestAnySkeleton.Create(''''Any Test Server'''', TMyTest.Create);
BOA.ObjIsReady(MyAnyTest as _Object);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitCorba;
end;
end.
接下来我们的客户程序如何获得这个字符串呢?
那么我们只需要在客户程序中去引用这个接口方法就够了,代码如下
unit ClientMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Corba, CRB_I, CRB_C;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FromIStr :TTestAny;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
CorbaInitialize;
FromIStr:= TTestAnyHelper.bind;//创建一个接口的实例
end;
procedure TForm1.Button1Click(Sender: TObject);
var myAny : Any;
begin
myAny := FromIStr.GetAny();//引用接口实例的方法
Label1.Caption := IntToStr(myany);
//将方法的结果转化为字符串,付给Label1.Caption
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FromIStr:= nil;
//释放接口实例对象
end;
end.
您理解上面的程序吗?下一小节我们将继续讲解如何传递一个数组对象,错误之处还请来函指正哟!下次再见
上一页 [1] [2] [系统软件]InstallShield Express for delphi制作安装程序定… [系统软件](转帖) 忘记登录密码的解决方案 for XP/2003/2000 [系统软件]交叉编译sshd for IXP425 ARM Platform by MVL 3… [Delphi程序]《关于VisiBroker For Delphi的使用》(4) [Delphi程序]一个超链接Image控件!(For D3,D4,D5,D6)源代码 [Delphi程序]Five of the best tools for Delphi [Delphi程序]《关于VisiBroker For Delphi的使用》(3) [Delphi程序]《关于VisiBroker For Delphi的使用》 [Delphi程序]Delphi for .Net 编译器预览 - by John Kaster [Delphi程序]编写一个单独的Web Service for Delphi7(步骤)
|