Here is my code:
///////////////////// udmMDS server side DataModle /////////////////////////
unit udmMDS;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Dialogs, Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, prjMDS_TLB, StdVcl, Provider, DB, ADODB, DBTables;
type
TmdRemoteServer = class(TRemoteDataModule, ImdRemoteServer)
dsMaster: TDataSource;
db: TDatabase;
session: TSession;
qryMaster: TQuery;
qryDetail: TQuery;
dspMaster: TDataSetProvider;
dspDetail: TDataSetProvider;
procedure qryMasterAfterScroll(DataSet: TDataSet);
private
m_strMasterSQL : string;
m_strDetailSQL : string;
m_strMasterFields : string;
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
procedure SetSQL(const strMasterSQL, strDetailSQL,
strMasterFields: WideString);
safecall;
public
{ Public declarations }
end;
implementation
{$R *.DFM}
class procedure TmdRemoteServer.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 TmdRemoteServer.SetSQL(const strMasterSQL, strDetailSQL,
strMasterFields: WideString);
begin
m_strMasterSQL := strMasterSQL;
m_strDetailSQL := strDetailSQL;
m_strMasterFields := strMasterFields;
qryMaster.Close;
qryMaster.SQL.Clear;
qryMaster.SQL.Add(m_strMasterSQL);
qryMaster.Open;
qryDetail.Close;
qryDetail.SQL.Clear;
qryDetail.SQL.Add(m_strDetailSQL);
qryDetail.Open;
end;
procedure TmdRemoteServer.qryMasterAfterScroll(DataSet: TDataSet);
var
strMasterField : string;
begin
qryDetail.Close;
qryDetail.SQL.Clear;
strMasterField := qryMaster.FieldByName('CustNo').AsString;
qryDetail.SQL.Add(m_strDetailSQL
+ ' where CustNo = "'
+ strMasterField + '"');
qryDetail.Open;
end;
initialization
TComponentFactory.Create(ComServer, TmdRemoteServer,
Class_mdRemoteServer, ciMultiInstance, tmApartment);
end.
///////////////////////// udmMDC client side DataModule //////////////////////
unit udmMDC;
interface
uses
SysUtils, Classes, DB, DBClient, MConnect, Dialogs;
type
TdmMDC = class(TDataModule)
con: TDCOMConnection;
cdsMaster: TClientDataSet;
cdsDetail: TClientDataSet;
dsMaster: TDataSource;
dsDetail: TDataSource;
procedure DataModuleCreate(Sender: TObject);
procedure cdsMasterAfterScroll(DataSet: TDataSet);
procedure DataModuleDestroy(Sender: TObject);
private
m_strMasterSQL : string;
m_strDetailSQL : string;
m_strMasterFields : string;
public
{ Public declarations }
end;
var
dmMDC: TdmMDC;
implementation
{$R *.dfm}
procedure TdmMDC.DataModuleCreate(Sender: TObject);
begin
con.Connected := true;
m_strMasterSQL := 'select * from customer';
m_strDetailSQL := 'select * from orders';
m_strMasterFields := 'CustNo';
con.AppServer.SetSQL(m_strMasterSQL, m_strDetailSQL, m_strMasterFields);
udmMDC.dmMDC.cdsMaster.Active := true;
udmMDC.dmMDC.cdsDetail.Active := true;
end;
procedure TdmMDC.cdsMasterAfterScroll(DataSet: TDataSet);
var
strMasterField : string;
begin
cdsDetail.Close;
strMasterField := cdsMaster.FieldByName('CustNo').AsString;
ShowMessage(strMasterField);
{
cdsDetail.CommandText := m_strDetailSQL
+ ' where CustNo = "'
+ strMasterField + '"';
}
cdsDetail.Open;
end;
procedure TdmMDC.DataModuleDestroy(Sender: TObject);
begin
con.Connected := false;
udmMDC.dmMDC.cdsMaster.Active := false;
udmMDC.dmMDC.cdsDetail.Active := false;
end;
end.