TSOCKETCONNECT和DCOMCONNECTION的问题,高手请进——>(300分)

  • 主题发起人 主题发起人 djdsz
  • 开始时间 开始时间
D

djdsz

Unregistered / Unconfirmed
GUEST, unregistred user!
在我的系统中,要将客户端统一使用IInterface进行操作,有如下的代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Corba, CorbaData_c, CorbaData_i, DB, DBClient, StdCtrls, Grids, DBGrids,
InvokeRegistry, Rio, SOAPHTTPClient, MConnect, SConnect,midas;
type
//SOAP连接接口
Icvdata = interface(IInvokable)
['{2F5CE239-D258-11F1-4C74-17CDCD4F895D}']
function GetDBMSName: String;safecall;
function GetDBTables(IncludeSysTable: Boolean): String;safecall;
function FetchDatas(SQL,Params:OleVariant;Compress:Boolean;
Local:String;Count:integer;OwnerData:OleVariant;
UseXML:Boolean): Olevariant;
safecall;
function SaveData(SQL, Data: olevariant;
MaxError: Integer;
var ErrorCount: Integer;
Compress: boolean;
const Local: String;USEXML:Boolean): olevariant;
safecall;
function ExecuteSQL(SQL: olevariant;
Params: olevariant;
const Local: String;USEXML:boolean):olevariant;
safecall;
function FetParams(const Local: String;
SQL: olevariant;USEXML:boolean): olevariant;
safecall;
end;

//传统的DCOM/SOCKET/WEB连接接口
Icvserverobj = interface(IAppServer)
['{E30F8E2F-A1D1-4692-A48D-FFE1EDD94D0B}']
function GetDBMSName: WideString;
safecall;
function GetDBTables(IncludeSysTable: WordBool): WideString;
safecall;
function FetchDatas(SQL: OleVariant;
var Params: OleVariant;
Compress: WordBool;
const Local: WideString;
Count: Integer;
OwnerData: OleVariant;
USEXML: WordBool): OleVariant;
safecall;
function SaveData(SQL: OleVariant;
Data: OleVariant;
MaxError: Integer;
out ErrorCount: Integer;
Compress: WordBool;
const Local: WideString;
USEXML: WordBool): OleVariant;
safecall;
function ExecuteSQL(SQL: OleVariant;
Params: OleVariant;
const Local: WideString;
Compress: WordBool): OleVariant;
safecall;
function FetParams(const Local: WideString;
SQL: OleVariant;
Compress: WordBool): OleVariant;
safecall;
end;

//CORBA接口
corbadata = interface
['{10FC111E-7B85-1554-2588-FCD52EFFFA0E}']
function GetDBMSName : AnsiString;
function GetDBTables (const IncludeSysTable : Boolean): AnsiString;
function FetchDatas (const SQL : Any;
var params : Any;
const Compress : Boolean;
const local : AnsiString;
const count : Integer;
const OwnerData : Any;
const USEXML : Boolean): Any;
function SaveData (const SQL : Any;
const Data : Any;
const MaxError : Integer;
out ErrorCount : Integer;
const Compress : Boolean;
const Local : AnsiString;
const USEXML : Boolean): Any;
function ExecuteSQL (const SQL : Any;
const Params : Any;
const Local : AnsiString;
const Compress : Boolean): Any;
function FetParams (const Local : AnsiString;
const SQL : Any;
const Compress : Boolean): Any;
end;

TForm1 = class(TForm)
Button1: TButton;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
HTTPRIO1: THTTPRIO;
CheckBox1: TCheckBox;
DCOMConnection1: TDCOMConnection;
SocketConnection1: TSocketConnection;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ private declarations }
protected
procedure InitCorba;
{ protected declarations }
public
{ public declarations }
end;

var
Form1: TForm1;
acct:corbadata;
implementation
uses variants;
{$R *.DFM}
procedure TForm1.InitCorba;
begin
CorbaInitialize;
Acct := TcorbadataHelper.bind;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
InitCorba;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
v:variant;
v1:olevariant;
i:integer;
t:tdatetime;
p:Icvserverobj;
begin
t:=now;
ClientDataSet1.Close;
v:=null;
v1:=v;
if checkbox1.Checked then
//CORBA
clientdataset1.Data:=acct.FetchDatas(vararrayof(['select * from appinf','select * from appinf where app_id=:app_id']),v,false,'CHS',-1,null,false)
else
begin
//传统的MIDAS
p:=SocketConnection1.GetServer as Icvserverobj;//错误,接口不支持,但使用DCOMConnection的时候就没问题
ClientDataSet1.Data:=p.FetchDatas(vararrayof(['select * from appinf','select * from appinf where app_id=:app_id']),v1,false,'CHS',-1,null,false);
p:=nil;
end;
//SOAP
ClientDataSet1.Data:=(httprio1 as icvdata).FetchDatas('select * from appinf',v,false,'CHS',-1,null,false);
showmessage(formatdatetime('hh:mm:ss:zzz',now-t));
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Acct:=nil;
end;

end.
大虾们看看,要得到服务器上的接口,DCOM可以用GetServer as Icvserverobj
为什么SOCKET就不行,SOCKET下该怎么用??
 
SOCKET不能使用。
 
SOCKET不能使用接口吗?
 
试试stdcall
 
DCom连接可以用早绑定,Socket连接是不能这么用的。
可以用晚绑定,SocketConnection.YoueMethod
但这样使用的效率很成问题,可以用IDispatch接口来冒充早绑定。
var
Intf: IEverydayInfoServerDisp;
begin
Intf:=IYourInterfaceDisp(IDispatch(SocketConnection.AppServer));
Intf.YourMethod
end;
 
socket用的TCP/IP协议,DCOM似乎用于局域网的。
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
928
SUNSTONE的Delphi笔记
S
后退
顶部