unit Unit2;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
  DBClient, Project1_TLB, StdVcl, Provider, DB, ADODB;

type
  TMyDcomServer = class(TRemoteDataModule, IMyDcomServer)
    ADOConnection1: TADOConnection;
    ADODataSet1: TADODataSet;
    DataSetProvider1: TDataSetProvider;
    procedure RemoteDataModuleCreate(Sender: TObject);
    procedure RemoteDataModuleDestroy(Sender: TObject);
    procedure ADODataSet1AfterOpen(DataSet: TDataSet);
  private
    { Private declarations }
  protected
    class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
    function Get_clientCount: Integer; safecall;
    procedure newQuery(SQLQuery: OleVariant); safecall;
  public
    { Public declarations }
  end;

implementation

uses Unit1;

{$R *.DFM}

class procedure TMyDcomServer.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 TMyDcomServer.RemoteDataModuleCreate(Sender: TObject);
begin
  intClient:= intClient+1;
  form1.lClientCount.Caption:=IntToStr(intClient);
end;

procedure TMyDcomServer.RemoteDataModuleDestroy(Sender: TObject);
begin
  intClient:= intClient-1;
  form1.lClientCount.Caption:=IntToStr(intClient);
end;

procedure TMyDcomServer.ADODataSet1AfterOpen(DataSet: TDataSet);
begin
  intQuery:= intQuery+1;
  form1.lQueryCount.Caption:=IntToStr(intQuery);
end;

function TMyDcomServer.Get_clientCount: Integer;
begin
  Get_clientCount:=intClient;
end;

procedure TMyDcomServer.newQuery(SQLQuery: OleVariant);
begin
    with ADODataset1 do
    begin
      if  SQLQuery<>'' then
      begin
        Close;
        CommandText:=SQLQuery;
        open;
      end;
    end;
end;

initialization
  TComponentFactory.Create(ComServer, TMyDcomServer,
    Class_MyDcomServer, ciMultiInstance, tmFree);
end.

