刚接触接口,不知如何使用?
我想在客户端通过socketconnect.AppServer.xxxx(xxxx)来调用服务器端的一个过程xxxx,但不知如何在客户端接收该过程返回的结果,不知服务器端要如何定义?谢谢!

解决方案 »

  1.   

    客户端用clientdataset, 用clientdataset.remoteserver:=your remote server.
    clientdataset.priveder:=your revote server.priveder
      

  2.   

    我这段过程只返回一串字符,我想达到的效果是:
    var s:string;
    begin
      s:=socketconnect.AppServer.xxxx(xxxx);
       .
       .
       .
    end;
    但S没有被赋值.
      

  3.   

    //****************************************************************
    //               Smart Agence SDK
    //               Copytright by National Union MicroSystem Co.Ltd
    // Author: 曾胡龙
    // 2002-08-23
    // WARNING
    //----------------------------------------------------------------unit uSaRemoteObjAdapter;interface
    uses
       SysUtils, Messages, Classes, Sconnect,Dialogs
       {$ifdef Ver140},Variants{$endif};type
        TSaRemoteObjAdapter = class(TComponent)
        private
         FSckt: TSocketConnection;
            FError: string;
            FWaitTimes:integer;
            FIsTryConnect:Boolean;
            FConnected:Boolean;
         function  GetAddress: string;
         function  GetIntercept: string;
         function  GetOleObject: Variant;
         function  GetServer: string;
         procedure SetAddress(const Value: string);
         procedure SetIntercept(const Value: string);
         procedure SetServer(const Value: string);
         function  GetPort: integer;
         procedure SetPort(const Value: integer);
         procedure SetOleObject(const Value: Variant);
         function  GetDispatchObject: IDispatch;
            procedure SetDispatchObject(const Value: IDispatch);
            function  DoConnect:Boolean;
            function  DoDisConnect:Boolean;
         property Error: string read FError;
         property OleObject: Variant read GetOleObject write SetOleObject;
         property DispatchObject: IDispatch read GetDispatchObject write SetDispatchObject;
         property Intercept: string read GetIntercept write SetIntercept;
        public
         constructor Create(AOwner: TComponent); override;
         destructor  Destroy; override;        procedure Sa_Request(const SaObjName, SaMethodName: WideString;SaIn: OleVariant; var SaOut: OleVariant); safecall;
            procedure Sa_Update(const SaObjName, SaMethodName: WideString;SaIn: OleVariant; var SaOut: OleVariant); safecall;
            procedure Sa_Execute(const SaObjName, SaMethodName: WideString;SaIn: OleVariant; var SaOut: OleVariant); safecall;     property Address: string read GetAddress write SetAddress;
         property Port: integer read GetPort write SetPort;
       property Server: string read GetServer write SetServer;
            property Connected :Boolean read FConnected write FConnected;
            property WaitTimes:integer read FWaitTimes write FWaitTimes;
            property IsTryConnect:Boolean read FIsTryConnect write FIsTryConnect;
        published    end;implementation
    { TSaRemoteObjAdapter }constructor TSaRemoteObjAdapter.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FSckt := TSocketConnection.Create(Self);
    end;destructor TSaRemoteObjAdapter.Destroy;
    begin
      FSckt.Close;
      FSckt.Free;
      inherited;
    end;function TSaRemoteObjAdapter.GetAddress: string;
    begin
        if FSckt.Address <> '' then
         Result := FSckt.Address
        else
         Result := FSckt.Host;
    end;function TSaRemoteObjAdapter.GetDispatchObject: IDispatch;
    begin
       Result := IDispatch(GetOleObject);
    end;function TSaRemoteObjAdapter.GetIntercept: string;
    begin
       {$ifdef Ver140}
        if (Length(FSckt.InterceptGUID) > 0) then
         Result := FSckt.InterceptGUID
        else
         Result := FSckt.InterceptName;
       {$else}
        if (Length(FSckt.InterceptGUID) > 0) then
         Result := FSckt.InterceptGUID;
       {$endif}
    end;function TSaRemoteObjAdapter.GetOleObject: Variant;
    begin
      try
        if not FSckt.Connected then FSckt.Open;
           Result := FSckt.AppServer;
      except
        on E: Exception do
           begin
             Result := Null;
             FError := E.Message;
           end;
      end;
    end;function TSaRemoteObjAdapter.GetPort: integer;
    begin
      Result  := FSckt.Port;
    end;function TSaRemoteObjAdapter.GetServer: string;
    begin
        if FSckt.ServerName <> '' then
         Result := FSckt.ServerName
        else
         Result := FSckt.ServerGuid;
    end;
    procedure TSaRemoteObjAdapter.Sa_Request(const SaObjName, SaMethodName: WideString;
      SaIn: OleVariant; var SaOut: OleVariant);
    begin
      if Connected = false then
      begin
        if not DoConnect then
           Exit;
      end;  try
        if Connected  = true then
        begin
          try
            OleObject.Sa_Request(SaObjName, SaMethodName,SaIn,SaOut);
          except
            on E:Exception do
               begin
                 Showmessage('[Remote Object Adapter Error]'+#13 + 'Native Error Information :'+ E.Message);
               end;
          end;
        end;
      finally  end;end;procedure TSaRemoteObjAdapter.Sa_Execute(const SaObjName, SaMethodName: WideString;
      SaIn: OleVariant; var SaOut: OleVariant);
    begin  if Connected = false then
      begin
        if not DoConnect then
           Exit;
      end;  try
        if Connected  = true then
        begin
          try
            OleObject.Sa_Execute(SaObjName, SaMethodName,SaIn,SaOut);
          except
            on E:Exception do
               begin
                 Showmessage('[Remote Object Adapter Error]'+#13 + 'Native Error Information :'+ E.Message);           end;
          end;
        end;
      finally  end;
    end;procedure TSaRemoteObjAdapter.Sa_Update(const SaObjName, SaMethodName: WideString;
      SaIn: OleVariant; var SaOut: OleVariant);
    begin
      if Connected = false then
      begin
        if not DoConnect then
           Exit;
      end;  try
        if Connected  = true then
        begin
           try
             OleObject.Sa_Update(SaObjName, SaMethodName,SaIn,SaOut);
           except
             on E:Exception do
                Showmessage('[Remote Object Adapter Error]'+#13 + 'Native Error Information :'+ E.Message);
           end;
        end;
      finally  end;
    end;procedure TSaRemoteObjAdapter.SetAddress(const Value: string);
    begin
        if Pos('.', Value) > 0 then
         FSckt.Address := Value
        else
         FSckt.Host := Value;
    end;procedure TSaRemoteObjAdapter.SetDispatchObject(const Value: IDispatch);
    begin
       if Value = nil then SetOleObject(Null);
    end;procedure TSaRemoteObjAdapter.SetIntercept(const Value: string);
    begin
        {$ifdef Ver140}
        if (Length(Value) > 0) and (Value[1] = '{') then
         FSckt.InterceptGUID := Value
        else
         FSckt.InterceptName := Value;
        {$else}
        if (Length(Value) > 0) and (Value[1] = '{') then
         FSckt.InterceptGUID := Value;
        {$endif}
    end;procedure TSaRemoteObjAdapter.SetOleObject(const Value: Variant);
    begin
        if VarType(Value) <= varNull then
         FSckt.Close;
    end;procedure TSaRemoteObjAdapter.SetPort(const Value: integer);
    begin
      if Trim(IntToStr(Value))<>'' then
      FSckt.Port := Value
      else
      FSckt.Port := 211;  //default Port
    end;procedure TSaRemoteObjAdapter.SetServer(const Value: string);
    begin
        if (Length(Value) > 0) and (Value[1] = '{') then
         FSckt.ServerGUID := Value
        else
         FSckt.ServerName := Value;
    end;
    function TSaRemoteObjAdapter.DoConnect: Boolean;
    begin
      Result := false;
      try
        try
          if FSckt.Connected = false then
          begin
            FSckt.Connected := true;
            FConnected := true;
            Result := true;
          end;
        except
          on E:Exception do
             begin
               Showmessage('[ Socket Connect Internal Error ]'+#13 + 'Native Error Information:'+ E.Message);
               FConnected := false;
               Result := false;
             end;
        end;
      finally  end;
    end;function TSaRemoteObjAdapter.DoDisConnect: Boolean;
    begin  Result := false;
      try
        try
          if FSckt.Connected then
          begin
            FSckt.Connected := false;
            FConnected := false;;
            Result := true;
          end;
        except
          on E:Exception do
             begin
               Result := false;
               FConnected := false;
               Showmessage('[Socket DisConnect Internal Error]'+#13 + 'Native Error Information :'+ E.Message);
             end;
        end;
      finally  end;
      
    end;end.
      

  4.   

    服务器端定义一个 OleVariant , out 类型的参数,将运行结果赋给这个参数
    客户端同样定义一个OleVariant的变量,在调用时,用个这变量做形参,socketconnect.AppServer.xxxx(变量)
    值带出来。