Board index » delphi » Adorecordset with MTS demo

Adorecordset with MTS demo

I try to pass a adorecordset from a MTS server to a client.
I think I have to do it via an OLEVariant.
Does anyone have a demo for delphi 5 ?

Thank you for you time.

Leo Huls

 

Re:Adorecordset with MTS demo


Hi,

Quote
> I try to pass a adorecordset from a MTS server to a client.
> I think I have to do it via an OLEVariant.
> Does anyone have a demo for delphi 5 ?

MTS Object:
------------------------------------

uses SysUtils, ComServ, ADODB_TLB;

{$DEFINE MitMTS}

function TMTSADORecordSet.GetOrte(const sPLZ: WideString): OleVariant;
var
  aConnection : _Connection;
  aRS         : _Recordset;
  swConnString: WideString;
  swSQL       : WideString;
begin
  {$IFDEF MitMTS}
  OleCheck(ObjectContext.CreateInstance(CLASS_Connection, _Connection,
                                        aConnection));
  OleCheck(ObjectContext.CreateInstance(CLASS_Recordset, _Recordset,
                                        aRS));
  {$ELSE}
  aConnection := CoConnection.Create;
  aRS := CoRecordset.Create;
  {$ENDIF}
  swConnString := 'Provider=SQLOLEDB.1;Persist Security Info=False;' +
                  'User ID=sa;Initial Catalog=IBImport;Data Source=(local)';
  // adUseClient, da die Connection wieder getrennt wird!
  aConnection.CursorLocation := adUseClient;
  aConnection.Open(swConnString, '', '', 0);
  swSQL := Format('SELECT ORT FROM ORTE WHERE PLZ = %s', [sPLZ]);
  aRS.Open(swSQL, aConnection, adOpenKeyset, adLockBatchOptimistic, 0);
  Result := aRS;
  aRS.Set_ActiveConnection(nil);
  aConnection.Close;
  {$IFDEF MitMTS}
  ObjectContext.SetComplete;
  {$ENDIF}
end;

Client:
-------------------------------

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, Db, ADODB, DBCtrls, Grids, DBGrids, ExtCtrls;

type
  TForm1 = class(TForm)
    StatusBar1: TStatusBar;
    Panel1: TPanel;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    ButtonGet: TButton;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    Label1: TLabel;
    EditPLZ: TEdit;
    procedure ButtonGetClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses MTSADORS_TLB;

procedure TForm1.ButtonGetClick(Sender: TObject);
var
  aSrv     : IMTSADORecordSet;
  vRS      : OleVariant;
  swSrvMsg : WideString;
begin
  aSrv := CoMTSADORecordSet.Create;
  vRS := aSrv.GetOrte(EditPLZ.Text);
  ADOTable1.Recordset := IDispatch(vRS) as _Recordset;
  ADOTable1.Active := True;
  StatusBar1.SimpleText := swSrvMsg;
end;

---

Good luck

Andy

Other Threads