type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
unit Server_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-24 0:46:21 from Type Library described below.
// *********************************************************************//
// The Class CoDCOMServerSL1 provides a Create and CreateRemote method to
// create instances of the default interface IDCOMServerSL1 exposed by
// the CoClass DCOMServerSL1. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoDCOMServerSL1 = class
class function Create: IDCOMServerSL1;
class function CreateRemote(const MachineName: string): IDCOMServerSL1;
end;
// *********************************************************************//
// The Class CoDCOMBackCall provides a Create and CreateRemote method to
// create instances of the default interface IDCOMBackCall exposed by
// the CoClass DCOMBackCall. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoDCOMBackCall = class
class function Create: IDCOMBackCall;
class function CreateRemote(const MachineName: string): IDCOMBackCall;
end;
implementation
uses ComObj;
class function CoDCOMServerSL1.Create: IDCOMServerSL1;
begin
Result := CreateComObject(CLASS_DCOMServerSL1) as IDCOMServerSL1;
end;
class function CoDCOMServerSL1.CreateRemote(const MachineName: string): IDCOMServerSL1;
begin
Result := CreateRemoteComObject(MachineName, CLASS_DCOMServerSL1) as IDCOMServerSL1;
end;
class function CoDCOMBackCall.Create: IDCOMBackCall;
begin
Result := CreateComObject(CLASS_DCOMBackCall) as IDCOMBackCall;
end;
class function CoDCOMBackCall.CreateRemote(const MachineName: string): IDCOMBackCall;
begin
Result := CreateRemoteComObject(MachineName, CLASS_DCOMBackCall) as IDCOMBackCall;
end;
type
TDCOMBackCall = class(TRemoteDataModule, IDCOMBackCall)
private
BackCallSL : OleVariant;
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
procedure GetInfos(var Infos: OleVariant); safecall;
public
{ Public declarations }
end;
implementation
{$R *.DFM}
class procedure TDCOMBackCall.UpdateRegistry(Register: Boolean; const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;
function TDCOMServerSL1.GetInfo(const UserName,
Pass: WideString): WordBool;
begin
if ( UserName <>'Server' ) or (Pass <>'Admin') then
begin
Result := False
end else
begin
Result := True;
Form1.Label1.Caption := '客户成功登录';
end;
{//////////////////////////////////////////////////////////////////////////////
/////////这个自己分析,如果说不会,那就惨喽
//////////////////////////////////////////////////////////////////////////////}
end;
procedure TDCOMServerSL1.Call;
begin
ShowMessage('aa'); //// or GetInfo(UserName,Pass);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
ClientVar := CoDCOMServerSL1.Create;
if ClientVar.GetInfo(Edit1.Text,Edit2.Text) then
begin
Application.MessageBox('恭喜您,登录成功!','操作提示',MB_OK + MB_ICONINFORMATION);
end else
begin
Application.MessageBox('对不起,登录失败!','操作提示',MB_OK + MB_ICONINFORMATION);
end;
/////////////////////////////////////////////////////////////////////////////////////
/////////MyDCOMConnection.AppServer.ProcName;,也可以用这种进行回调
/////////CoDCOMBackCall = class
/////////class function Create: IDCOMBackCall;
////////class function CreateRemote(const MachineName: string): IDCOMBackCall;
////////end;
////////看一看它的定义,它其实是一个类,呵呵,协同接口类;是实现一个或多个接口的类,
///////有一个类生成库和一个类标识器;
///////这一部分是DCOM的,和回调无关;
///////////////////////////////////////////////////////////////////////////////////////
end;
{ TClientCallBack }
procedure TForm2.FormCreate(Sender: TObject);
var
TypeLib : ITypeLib;
begin
MyDCOMConnection := SocketConnection1;
MyDCOMConnection.Connected := True;
OLECheck(LoadRegTypeLib(LIBID_Server,0,0,1,TypeLib));
MyDCOMConnection.AppServer.GetInfos(FClientCallBack as IDispatch);
{/////////////////////////////////////////////////////////////////////////////
//////MyDCOMConnection := SocketConnection1;是回调的关键,你要用它来代替TSocketConnection,操作还是类实例之间,你明白吗?
//////MyDCOMConnection.Connected := True;还用说吗?
//////OLECheck(LoadRegTypeLib(LIBID_Server,0,0,1,TypeLib));在客户端注册;
//////MyDCOMConnection.AppServer.GetInfos(FClientCallBack as IDispatch);开始执行,而且进行接口转化;
//////TypeLib : ITypeLib;可以应用类型库类 Uses ActiveX;
//////////////////////////////////////////////////////////////////////////////}
end;