中间层:
unit uFrmRDM;{$WARN SYMBOL_PLATFORM OFF}interfaceuses
  Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
  DBClient, scmserver_TLB, StdVcl, Provider, DB, ADODB, DBTables;type
  TFrmRDM = class(TRemoteDataModule, IFrmRDM)
    ADOConnection1: TADOConnection;
    adoBM: TADOQuery;
    dspBM: TDataSetProvider;
    dspNUM: TDataSetProvider;
    adoNUM: TADOQuery;
    Session1: TSession;
  private
    { Private declarations }
  protected
    class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
    function GetNewNum(TableName:string;FieldName:string):string ;
    function GetDate:tdatetime ;
    function GetDateTime:tdatetime ;
    procedure Select(var TableName, Qstr:string); safecall;
  public
    { Public declarations }
  end;implementation{$R *.DFM}class procedure TFrmRDM.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;procedure TFrmRDM.Select(var TableName, Qstr: string);
begin
  if TableName='bm' then
  begin
    adobm.Close;
    adobm.SQL.Add('select * from bm where 1=1'+Qstr+'order by bmdm');
    adobm.Open;
  end;end;function TFrmRDM.GetNewNum(TableName:string;FieldName:string):string ;
var
  maxnum,temp,inputnum :string;
  newnum :integer;
begin
  adoNUM.Close;
  adoNUM.SQL.text :='select max('+FieldName+') ×?′ó±ào? from '+TableName;
  adoNUM.Open;
  maxnum:=adoNUM.fieldbyname('×?′ó±ào?').AsString;
  if trim(maxnum)='' then
  begin
    temp:='00000000';
  end
  else
  begin
    temp:=copy(maxnum,1,8);
  end;
  newnum:=strtoint(temp)+1;
  if length(inttostr(newnum))=1 then
  begin
    inputnum:='0000000'+inttostr(newnum);
  end;
  if length(inttostr(newnum))=2 then
  begin
    inputnum:='000000'+inttostr(newnum);
  end;
  if length(inttostr(newnum))=3 then
  begin
    inputnum:='00000'+inttostr(newnum);
  end;
  if length(inttostr(newnum))=4 then
  begin
    inputnum:='0000'+inttostr(newnum);
  end;
  if length(inttostr(newnum))=5 then
  begin
    inputnum:='000'+inttostr(newnum);
  end;
  if length(inttostr(newnum))=6 then
  begin
    inputnum:='00'+inttostr(newnum);
  end;
  if length(inttostr(newnum))=7 then
  begin
    inputnum:='0'+inttostr(newnum);
  end;
  if length(inttostr(newnum))=8 then
  begin
    inputnum:=inttostr(newnum);
  end;
  result:=inputnum;
end;function TFrmRDM.GetDate:tdatetime ;
begin
  result:=date;
end;function TFrmRDM.GetDateTime:tdatetime ;
begin
  result:=now;
end;initialization
  TComponentFactory.Create(ComServer, TFrmRDM,
    Class_FrmRDM, ciMultiInstance, tmApartment);
end.
客户端:
unit uFrmBM;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uFrmChild, fcButton, fcImgBtn, fcShapeBtn, ExtCtrls, ComCtrls,
  dxtree, dxdbtree,uFrmDM, DB, ADODB, StdCtrls, DBCtrls, dxCntner,
  dxEditor, dxEdLib, dxDBELib, dxExEdtr, Mask;type
  TFrmBM = class(TFrmChild)
    Panel2: TPanel;
    Panel3: TPanel;
    dxDBTreeView1: TdxDBTreeView;
    ADODataSet1: TADODataSet;
    ADODataSet1BMDM: TStringField;
    ADODataSet1SJBMDM: TStringField;
    ADODataSet1BMMC: TStringField;
    ADODataSet1BMJB: TIntegerField;
    ADODataSet1MJBZ: TIntegerField;
    ADODataSet1BMSX: TIntegerField;
    DataSource1: TDataSource;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    RgBMSX: TDBRadioGroup;
    EdtBMMC: TdxDBEdit;
    EdtBMJB: TdxDBEdit;
    EdtSJBMDM: TdxDBEdit;
    ChkMJBZ: TdxDBCheckEdit;
    GroupBox1: TGroupBox;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label5: TLabel;
    dxEdit1: TdxEdit;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    iStyle:integer;     //0±íê?D??¨£?1±íê?DT???ò??é?3y£?2±íê?2é?ˉ
    sParentCode:string;       //±íê?é???′ú??
    iParentJB:integer;        //±íê?é?????±e
    bParentMJBZ:boolean;      // ±íê?é????′??±ê??×′ì?
    procedure Setbutton;      //  ?ù?YiStyle?μà′éè?????t×′ì?
  public
    { Public declarations }
  end;var
  FrmBM: TFrmBM;implementation{$R *.dfm}procedure TFrmBM.Setbutton;
begin
  if iStyle=0 then     //D??¨
  begin
    btnCancel.Enabled:=true;
    btnOK.Enabled:=true;
    btnDel.Enabled:=false;
    btnNew.Enabled:=false;
    btnPrint.Enabled:=false;
    btnQuery.Enabled:=false;
    btnUpdate.Enabled:=false;
  end;
  if iStyle=1 then    // DT??
  begin
    btnCancel.Enabled:=true;
    btnOK.Enabled:=true;
    btnDel.Enabled:=false;
    btnNew.Enabled:=false;
    btnPrint.Enabled:=false;
    btnQuery.Enabled:=false;
    btnUpdate.Enabled:=false;
  end;
  if iStyle=2 then     // 2é?ˉ
  begin
    btnCancel.Enabled:=false;
    btnOK.Enabled:=false;
    btnDel.Enabled:=true;
    btnNew.Enabled:=true;
    btnPrint.Enabled:=true;
    btnQuery.Enabled:=true;
    btnUpdate.Enabled:=true;
  end;
end;procedure TFrmBM.FormShow(Sender: TObject);
begin
  inherited;
  iParentJB := 0;
  sParentCode := '';
  bParentMJBZ := False;
  FrmDM.SocketConnection1.AppServer.select('bm','');
  iStyle:=2;
  Setbutton;
end;                       end.
当客户端运行到  FrmDM.SocketConnection1.AppServer.select('bm','');时
就会报错,说
project scmclient.exe raised exception class EOleError with message 'variant does not reference an automation object'. Process stopped. Use Step or Run to continue;

解决方案 »

  1.   

    ADODataSet1.AppServer.中间层的方法名
      

  2.   

    这是tlb文件
    unit scmserver_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 2006-9-9 17:29:19 from Type Library described below.// ************************************************************************  //
    // Type Lib: D:\½øÏú´æ\·þÎñÆ÷¶Ë\scmserver.tlb (1)
    // LIBID: {7268879A-891C-4F7A-ADF7-57ABD71E85C9}
    // LCID: 0
    // Helpfile: 
    // DepndLst: 
    //   (1) v1.0 Midas, (C:\WINDOWS\system32\midas.dll)
    //   (2) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
    //   (3) v4.0 StdVCL, (C:\WINDOWS\system32\stdvcl40.dll)
    // ************************************************************************ //
    {$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
    {$WARN SYMBOL_PLATFORM OFF}
    {$WRITEABLECONST ON}interfaceuses ActiveX, Classes, Graphics, Midas, StdVCL, Variants, Windows;
      
    // *********************************************************************//
    // GUIDS declared in the TypeLibrary. Following prefixes are used:        
    //   Type Libraries     : LIBID_xxxx                                      
    //   CoClasses          : CLASS_xxxx                                      
    //   DISPInterfaces     : DIID_xxxx                                       
    //   Non-DISP interfaces: IID_xxxx                                        
    // *********************************************************************//
    const
      // TypeLibrary Major and minor versions
      scmserverMajorVersion = 1;
      scmserverMinorVersion = 0;  LIBID_scmserver: TGUID = '{7268879A-891C-4F7A-ADF7-57ABD71E85C9}';  IID_IFrmRDM: TGUID = '{9728D97E-F30F-408D-8648-11B44CA61948}';
      CLASS_FrmRDM: TGUID = '{073E9318-A239-4089-900B-96CD9447ECDD}';
    type// *********************************************************************//
    // Forward declaration of types defined in TypeLibrary                    
    // *********************************************************************//
      IFrmRDM = interface;
      IFrmRDMDisp = dispinterface;// *********************************************************************//
    // Declaration of CoClasses defined in Type Library                       
    // (NOTE: Here we map each CoClass to its Default Interface)              
    // *********************************************************************//
      FrmRDM = IFrmRDM;
    // *********************************************************************//
    // Declaration of structures, unions and aliases.                         
    // *********************************************************************//
      POleVariant1 = ^OleVariant; {*}
    // *********************************************************************//
    // Interface: IFrmRDM
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {9728D97E-F30F-408D-8648-11B44CA61948}
    // *********************************************************************//
      IFrmRDM = interface(IAppServer)
        ['{9728D97E-F30F-408D-8648-11B44CA61948}']
      end;// *********************************************************************//
    // DispIntf:  IFrmRDMDisp
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {9728D97E-F30F-408D-8648-11B44CA61948}
    // *********************************************************************//
      IFrmRDMDisp = dispinterface
        ['{9728D97E-F30F-408D-8648-11B44CA61948}']
        function  AS_ApplyUpdates(const ProviderName: WideString; Delta: OleVariant; 
                                  MaxErrors: Integer; out ErrorCount: Integer; var OwnerData: OleVariant): OleVariant; dispid 20000000;
        function  AS_GetRecords(const ProviderName: WideString; Count: Integer; out RecsOut: Integer; 
                                Options: Integer; const CommandText: WideString; 
                                var Params: OleVariant; var OwnerData: OleVariant): OleVariant; dispid 20000001;
        function  AS_DataRequest(const ProviderName: WideString; Data: OleVariant): OleVariant; dispid 20000002;
        function  AS_GetProviderNames: OleVariant; dispid 20000003;
        function  AS_GetParams(const ProviderName: WideString; var OwnerData: OleVariant): OleVariant; dispid 20000004;
        function  AS_RowRequest(const ProviderName: WideString; Row: OleVariant; RequestType: Integer; 
                                var OwnerData: OleVariant): OleVariant; dispid 20000005;
        procedure AS_Execute(const ProviderName: WideString; const CommandText: WideString; 
                             var Params: OleVariant; var OwnerData: OleVariant); dispid 20000006;
      end;// *********************************************************************//
    // The Class CoFrmRDM provides a Create and CreateRemote method to          
    // create instances of the default interface IFrmRDM exposed by              
    // the CoClass FrmRDM. The functions are intended to be used by             
    // clients wishing to automate the CoClass objects exposed by the         
    // server of this typelibrary.                                            
    // *********************************************************************//
      CoFrmRDM = class
        class function Create: IFrmRDM;
        class function CreateRemote(const MachineName: string): IFrmRDM;
      end;implementationuses ComObj;class function CoFrmRDM.Create: IFrmRDM;
    begin
      Result := CreateComObject(CLASS_FrmRDM) as IFrmRDM;
    end;class function CoFrmRDM.CreateRemote(const MachineName: string): IFrmRDM;
    begin
      Result := CreateRemoteComObject(MachineName, CLASS_FrmRDM) as IFrmRDM;
    end;end.
      

  3.   

    tlb文件里压根儿就没有select这个方法,你怎么能调用呢;
    借宝地一用,招个人:
    http://community.csdn.net/Expert/topic/5010/5010359.xml
      

  4.   

    要在 TLB 里加才行. 用 View -> Type Library 来加
      

  5.   

    需要添加接口,用 View -> Type Library 来加
      

  6.   

    试了的,现在,我通过Type Library 加了SELECT方法后,在FrmRDM这个窗体中将代码写入后,在客户端运行时,还是报这个错
      

  7.   

    代码如下
    TLB文件如下:
    unit scmserver_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 2006-9-11 16:30:15 from Type Library described below.// ************************************************************************  //
    // Type Lib: D:\???ú′?\·t???÷??\scmserver.tlb (1)
    // LIBID: {7268879A-891C-4F7A-ADF7-57ABD71E85C9}
    // LCID: 0
    // Helpfile: 
    // DepndLst: 
    //   (1) v1.0 Midas, (C:\WINDOWS\system32\midas.dll)
    //   (2) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
    //   (3) v4.0 StdVCL, (C:\WINDOWS\system32\stdvcl40.dll)
    // ************************************************************************ //
    {$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
    {$WARN SYMBOL_PLATFORM OFF}
    {$WRITEABLECONST ON}interfaceuses ActiveX, Classes, Graphics, Midas, StdVCL, Variants, Windows;
      
    // *********************************************************************//
    // GUIDS declared in the TypeLibrary. Following prefixes are used:        
    //   Type Libraries     : LIBID_xxxx                                      
    //   CoClasses          : CLASS_xxxx                                      
    //   DISPInterfaces     : DIID_xxxx                                       
    //   Non-DISP interfaces: IID_xxxx                                        
    // *********************************************************************//
    const
      // TypeLibrary Major and minor versions
      scmserverMajorVersion = 1;
      scmserverMinorVersion = 0;  LIBID_scmserver: TGUID = '{7268879A-891C-4F7A-ADF7-57ABD71E85C9}';  IID_IFrmRDM: TGUID = '{9728D97E-F30F-408D-8648-11B44CA61948}';
      CLASS_FrmRDM: TGUID = '{073E9318-A239-4089-900B-96CD9447ECDD}';
    type// *********************************************************************//
    // Forward declaration of types defined in TypeLibrary                    
    // *********************************************************************//
      IFrmRDM = interface;
      IFrmRDMDisp = dispinterface;// *********************************************************************//
    // Declaration of CoClasses defined in Type Library                       
    // (NOTE: Here we map each CoClass to its Default Interface)              
    // *********************************************************************//
      FrmRDM = IFrmRDM;
    // *********************************************************************//
    // Declaration of structures, unions and aliases.                         
    // *********************************************************************//
      POleVariant1 = ^OleVariant; {*}
    // *********************************************************************//
    // Interface: IFrmRDM
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {9728D97E-F30F-408D-8648-11B44CA61948}
    // *********************************************************************//
      IFrmRDM = interface(IAppServer)
        ['{9728D97E-F30F-408D-8648-11B44CA61948}']
        procedure Select(var TableName: OleVariant; var Qstr: OleVariant); safecall;
        procedure GetNewNumber(var TableName: OleVariant; var FieldName: OleVariant; 
                               out NewNumber: OleVariant); safecall;
      end;// *********************************************************************//
    // DispIntf:  IFrmRDMDisp
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {9728D97E-F30F-408D-8648-11B44CA61948}
    // *********************************************************************//
      IFrmRDMDisp = dispinterface
        ['{9728D97E-F30F-408D-8648-11B44CA61948}']
        procedure Select(var TableName: OleVariant; var Qstr: OleVariant); dispid 3;
        procedure GetNewNumber(var TableName: OleVariant; var FieldName: OleVariant; 
                               out NewNumber: OleVariant); dispid 5;
        function  AS_ApplyUpdates(const ProviderName: WideString; Delta: OleVariant; 
                                  MaxErrors: Integer; out ErrorCount: Integer; var OwnerData: OleVariant): OleVariant; dispid 20000000;
        function  AS_GetRecords(const ProviderName: WideString; Count: Integer; out RecsOut: Integer; 
                                Options: Integer; const CommandText: WideString; 
                                var Params: OleVariant; var OwnerData: OleVariant): OleVariant; dispid 20000001;
        function  AS_DataRequest(const ProviderName: WideString; Data: OleVariant): OleVariant; dispid 20000002;
        function  AS_GetProviderNames: OleVariant; dispid 20000003;
        function  AS_GetParams(const ProviderName: WideString; var OwnerData: OleVariant): OleVariant; dispid 20000004;
        function  AS_RowRequest(const ProviderName: WideString; Row: OleVariant; RequestType: Integer; 
                                var OwnerData: OleVariant): OleVariant; dispid 20000005;
        procedure AS_Execute(const ProviderName: WideString; const CommandText: WideString; 
                             var Params: OleVariant; var OwnerData: OleVariant); dispid 20000006;
      end;// *********************************************************************//
    // The Class CoFrmRDM provides a Create and CreateRemote method to          
    // create instances of the default interface IFrmRDM exposed by              
    // the CoClass FrmRDM. The functions are intended to be used by             
    // clients wishing to automate the CoClass objects exposed by the         
    // server of this typelibrary.                                            
    // *********************************************************************//
      CoFrmRDM = class
        class function Create: IFrmRDM;
        class function CreateRemote(const MachineName: string): IFrmRDM;
      end;implementationuses ComObj;class function CoFrmRDM.Create: IFrmRDM;
    begin
      Result := CreateComObject(CLASS_FrmRDM) as IFrmRDM;
    end;class function CoFrmRDM.CreateRemote(const MachineName: string): IFrmRDM;
    begin
      Result := CreateRemoteComObject(MachineName, CLASS_FrmRDM) as IFrmRDM;
    end;end.
      

  8.   

    客户端:
    unit uFrmBM;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, uFrmChild, fcButton, fcImgBtn, fcShapeBtn, ExtCtrls, ComCtrls,
      dxtree, dxdbtree,uFrmDM, DB, ADODB, StdCtrls, DBCtrls, dxCntner,
      dxEditor, dxEdLib, dxDBELib, dxExEdtr, Mask;type
      TFrmBM = class(TFrmChild)
        Panel2: TPanel;
        Panel3: TPanel;
        dxDBTreeView1: TdxDBTreeView;
        ADODataSet1: TADODataSet;
        ADODataSet1BMDM: TStringField;
        ADODataSet1SJBMDM: TStringField;
        ADODataSet1BMMC: TStringField;
        ADODataSet1BMJB: TIntegerField;
        ADODataSet1MJBZ: TIntegerField;
        ADODataSet1BMSX: TIntegerField;
        DataSource1: TDataSource;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        RgBMSX: TDBRadioGroup;
        EdtBMMC: TdxDBEdit;
        EdtBMJB: TdxDBEdit;
        EdtSJBMDM: TdxDBEdit;
        ChkMJBZ: TdxDBCheckEdit;
        GroupBox1: TGroupBox;
        Label11: TLabel;
        Label12: TLabel;
        Label13: TLabel;
        Label5: TLabel;
        dxEdit1: TdxEdit;
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
        iStyle:integer;     //0±íê?D??¨£?1±íê?DT???ò??é?3y£?2±íê?2é?ˉ
        sParentCode:string;       //±íê?é???′ú??
        iParentJB:integer;        //±íê?é?????±e
        bParentMJBZ:boolean;      // ±íê?é????′??±ê??×′ì?
        procedure Setbutton;      //  ?ù?YiStyle?μà′éè?????t×′ì?
      public
        { Public declarations }
      end;var
      FrmBM: TFrmBM;implementation{$R *.dfm}procedure TFrmBM.Setbutton;
    begin
      if iStyle=0 then     //D??¨
      begin
        btnCancel.Enabled:=true;
        btnOK.Enabled:=true;
        btnDel.Enabled:=false;
        btnNew.Enabled:=false;
        btnPrint.Enabled:=false;
        btnQuery.Enabled:=false;
        btnUpdate.Enabled:=false;
      end;
      if iStyle=1 then    // DT??
      begin
        btnCancel.Enabled:=true;
        btnOK.Enabled:=true;
        btnDel.Enabled:=false;
        btnNew.Enabled:=false;
        btnPrint.Enabled:=false;
        btnQuery.Enabled:=false;
        btnUpdate.Enabled:=false;
      end;
      if iStyle=2 then     // 2é?ˉ
      begin
        btnCancel.Enabled:=false;
        btnOK.Enabled:=false;
        btnDel.Enabled:=true;
        btnNew.Enabled:=true;
        btnPrint.Enabled:=true;
        btnQuery.Enabled:=true;
        btnUpdate.Enabled:=true;
      end;
    end;procedure TFrmBM.FormShow(Sender: TObject);
    begin
      inherited;
      iParentJB := 0;
      sParentCode := '';
      bParentMJBZ := False;
      FrmDM.SocketConnection1.AppServer.select('bm','');
      iStyle:=2;
      Setbutton;
    end;                       end.
      

  9.   

    看看你的SocketConnection1.Connection属性是否为TRUE