unit fmuMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComObj,
  //
  DCOMTSvr_TLB;

type
  TfmMain = class(TForm)
    btnConnect: TButton;
    btnDisconnect: TButton;
    lblGetValue: TLabel;
    procedure btnConnectClick(Sender: TObject);
    procedure btnDisconnectClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    fConnectionTime: DWORD;
    fobj: IDCOMTIntf;
  end;

var
  fmMain: TfmMain;

implementation

{$R *.DFM}

procedure TfmMain.btnConnectClick(Sender: TObject);
const
  bDCOMConnection: Boolean = True; {!!! поменяй для тестирования}
begin
  fConnectionTime := GetTickCount;
  if bDCOMConnection then
    fobj := CreateRemoteComObject('MARAT', Class_DCOMTObject) as IDCOMTIntf
  else
    fObj := CreateComObject(Class_DCOMTObject) as IDCOMTIntf;
  fConnectionTime := GetTickCount - fConnectionTime;
  lblGetValue.Caption := IntToStr(fobj.GetValue);
end;

procedure TfmMain.btnDisconnectClick(Sender: TObject);
begin
  fObj := nil;
  lblGetValue.Caption := 'NoValue';
end;

procedure TfmMain.FormDestroy(Sender: TObject);
begin
  fobj := nil; // можно не писать
end;

end.
