Board index » delphi » How to send ADORecordSet to another COM server?

How to send ADORecordSet to another COM server?

Hello, All!
I'm working in D5. I'd like to publish method of COM interface with
result-type : TADODataSet
(I want to use it in another COM server/ASP). There are no ADO types in list
to choose.
How can I do it?
 

Re:How to send ADORecordSet to another COM server?


Hi,

Quote
> I'm working in D5. I'd like to publish method of COM interface with
> result-type : TADODataSet
> (I want to use it in another COM server/ASP). There are no ADO types in
list
> to choose.
> How can I do it?

Server:

type
  TADOServer = class(TAutoObject, IADOServer)
  protected
    function ReturnRS: OleVariant; safecall;
    procedure SubmitRS(RS: OleVariant; out Msg: WideString); safecall;
    { Protected-Deklarationen }
  end;

implementation

uses ComServ, ADODB_TLB, SysUtils;

resourcestring
  cConnStr = 'Provider=Microsoft.Jet.OLEDB.4.0;' +
             'Data Source=C:\Database\dbdemos.mdb;' +
             'Persist Security Info=False';

function TADOServer.ReturnRS: OleVariant;
var
  adoCon1: _Connection;
  adoRs1: _Recordset;
begin
  adoCon1 := CoConnection.Create;
  adoRs1 := CoRecordset.Create;
  adoCon1.CursorLocation := adUseClient;
  adoCon1.Open(cConnStr, '', '', 0);
  adoRs1.Open('SELECT * FROM Country', adoCon1, adOpenKeyset,
              adLockBatchOptimistic, 0);
  // sent ADO-Recordset back to Client
  Result := adoRs1;
  adoRs1.Set_ActiveConnection(nil);
  adoCon1.Close;
end;

Client:

uses ADOSrv_TLB;

procedure TForm1.ButtonGetClick(Sender: TObject);
var
  aSrv : IADOServer;
  aRS  : _Recordset;
begin
  aSrv := CoADOServer.Create;
  aRS := IDispatch(aSrv.ReturnRS) as _Recordset;
  ADOTable1.Recordset := aRS;
  ADOTable1.Active := True;
end;

---

Good luck

Andy

Other Threads