各位老大,谁能给个Corba CallBack的Demo,在下感激不尽!(200分)

  • 主题发起人 主题发起人 xtalk
  • 开始时间 开始时间
X

xtalk

Unregistered / Unconfirmed
GUEST, unregistred user!
Server如何能在任何时候调用Client的接口?
注意:是Corba,不是DCOM
 
为什么没人理我?
嫌分不够吗?
 
据说visibroker不支持CallBack。
 
我试过了,可以,但接收到的数据不能调用ShowMessage,不知道为什么?下面是代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, CorbaDM_TLB,
StdCtrls, corbaobj;
type
TCallBack = class(TCorbaImplementation, ICallBack)
protected
procedure Recv(Data: OleVariant;
TargetID: Integer);
safecall;
end;

TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
FCallBack: TCallBack;
CorbaServer: ICorbaServer;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Str: String;
implementation
{$R *.DFM}
procedure OnData();
begin
//这里就停止了,不知道为什么?
//把ShowMessage去掉,一切正常
ShowMessage(Str);
Sleep(100);
end;

function ConvertPointer(Data: Pointer;
Size: Integer): Variant;
var
P: Pointer;
begin
Result := VarArrayCreate([0, Size], VarByte);
p := VarArrayLock(Result);
CopyMemory(p, Data, Size);
VarArrayUnlock(Result);
end;

function ConvertVariant(Data: Variant): Pointer;
var
p: Pointer;
begin
GetMem(Result, SizeOf(Data));
p := VarArrayLock(Data);
CopyMemory(Result, p, SizeOf(Data));
VarArrayUnlock(Data);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
// CORBAInitialize;
FCallBack := TCallBack.Create(nil, nil);
CorbaServer := TCorbaServerCorbaFactory.CreateInstance('');
CorbaServer.Register(FCallBack, 1);
end;

{ TCorbaServer }
procedure TCallBack.Recv(Data: OleVariant;
TargetID: Integer);
var
p: Pointer;
test: Ttest;
begin
p := ConvertVariant(Data);
Test := TTest(p^);
Str := test.Str;
// OnData();
end;

procedure TForm1.Button2Click(Sender: TObject);
var
Test: TTest;
begin
Test.Msg := 1;
Test.Str := 'KenII';
while Truedo
CorbaServer.Send(ConvertPointer(@Test, SizeOf(TTest)), 1);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Caption := Str;
end;

end.
 
callback功能要gatekeeper才能办到,但好像delphi不能使用gatekeeper。
java可以的。
 
VisiBroker for Delphi不支持事件服务,换用Java或CB吧
 
I want to know.
 
对你的代码改了改,已经发给你了!
 
接受答案了.
 
后退
顶部