unit ClientModuleUnit1;

interface

uses
  System.SysUtils, System.Classes, ClientClassesUnit1, Data.DBXDataSnap,
  IndyPeerImpl, Data.DBXCommon, Data.DB, Data.SqlExpr;

type
  TClientModule1 = class(TDataModule)
    SQLConnection1: TSQLConnection;
  private
    FInstanceOwner: Boolean;
    FMyServerMethodsClient: TMyServerMethodsClient;
    function GetMyServerMethodsClient: TMyServerMethodsClient;
    { Private declarations }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property InstanceOwner: Boolean read FInstanceOwner write FInstanceOwner;
    property MyServerMethodsClient: TMyServerMethodsClient read GetMyServerMethodsClient write FMyServerMethodsClient;

end;

var
  ClientModule1: TClientModule1;

implementation

{$R *.dfm}

{%CLASSGROUP 'System.Classes.TPersistent'}

constructor TClientModule1.Create(AOwner: TComponent);
begin
  inherited;
  FInstanceOwner := True;
end;

destructor TClientModule1.Destroy;
begin
  FMyServerMethodsClient.Free;
  inherited;
end;

function TClientModule1.GetMyServerMethodsClient: TMyServerMethodsClient;
begin
  if FMyServerMethodsClient = nil then
  begin
    SQLConnection1.Open;
    FMyServerMethodsClient:= TMyServerMethodsClient.Create(SQLConnection1.DBXConnection, FInstanceOwner);
  end;
  Result := FMyServerMethodsClient;
end;

end.
