unit ActiveHomeScriptLib;

// ************************************************************************ //
// This unit is a revised version of the imported type library
// ActiveHomeScriptLib_TLB.pas with three changes
//
//  1. The protected procedure
//     TOleControl.InvokeEvent(DispID: TDispID; var Params: TDispParams);
//     is overriden in the TActiveHome class to correct for the parameter
//     error on receiving messages from the ahscript.dll as per
//     ddv2005's January 04, 2008 message on the X10 forum
//     http://forums.x10.com/index.php?topic=14192.msg79406#msg79406
//
//  2. The default value of property TActiveHome.visible is changed to
//     false. To do this, the constructor is overriden.
//
//  3. A boolean function TActiveHome.TransceiverPresent: boolean; is added
//     to report on the presence of a connected CM15A.
//
//  Michel Deslierres 2013/07/15
// ************************************************************************ //

// $Rev: 17244 $
// File generated on 2013-07-11 11:17:28 from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\Program Files (x86)\Common Files\X10\Common\ahscript.dll (1)
// LIBID: {001000AF-1DEF-0010-10B6-DC5BA692C858}
// LCID: 0
// Helpfile: 
// HelpString: ActiveHomeScript 1.0 Type Library
// DepndLst: 
//   (1) v2.0 stdole, (C:\Windows\SysWOW64\stdole2.tlb)
// ************************************************************************ //
// *************************************************************************//
// NOTE:                                                                      
// Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties  
// which return objects that may need to be explicitly created via a function 
// call prior to any access via the property. These items have been disabled
// in order to prevent accidental use from within the object inspector. You
// may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively   
// removing them from the $IFDEF blocks. However, such items must still be    
// programmatically created via a method of the appropriate CoClass before    
// they can be used.                                                          
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
{$ALIGN 4}
interface

uses Windows, ActiveX, Classes, Graphics, OleCtrls, OleServer, StdVCL, Variants;


// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:        
//   Type Libraries     : LIBID_xxxx                                      
//   CoClasses          : CLASS_xxxx                                      
//   DISPInterfaces     : DIID_xxxx                                       
//   Non-DISP interfaces: IID_xxxx                                        
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  ActiveHomeScriptLibMajorVersion = 1;
  ActiveHomeScriptLibMinorVersion = 0;

  LIBID_ActiveHomeScriptLib: TGUID = '{001000AF-1DEF-0010-10B6-DC5BA692C858}';

  IID__IActiveHomeEvents: TGUID = '{001000AF-3DEF-0912-10B6-DC5BA692C858}';
  DIID__DIActiveHomeEvents: TGUID = '{001000AF-3DEF-0911-10B6-DC5BA692C858}';
  IID_IActiveHome: TGUID = '{001000AF-3DEF-0910-10B6-DC5BA692C858}';
  CLASS_ActiveHome: TGUID = '{001000AF-2DEF-0208-10B6-DC5BA692C858}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
  _IActiveHomeEvents = interface;
  _DIActiveHomeEvents = dispinterface;
  IActiveHome = interface;
  IActiveHomeDisp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library                       
// (NOTE: Here we map each CoClass to its Default Interface)              
// *********************************************************************//
  ActiveHome = IActiveHome;


// *********************************************************************//
// Interface: _IActiveHomeEvents
// Flags:     (0)
// GUID:      {001000AF-3DEF-0912-10B6-DC5BA692C858}
// *********************************************************************//
  _IActiveHomeEvents = interface(IUnknown)
    ['{001000AF-3DEF-0912-10B6-DC5BA692C858}']
    function RecvAction(bszAction: OleVariant; bszParm1: OleVariant; bszParm2: OleVariant; 
                        bszParm3: OleVariant; bszParm4: OleVariant; bszParm5: OleVariant; 
                        bszReserved: OleVariant): HResult; stdcall;
  end;

// *********************************************************************//
// DispIntf:  _DIActiveHomeEvents
// Flags:     (4096) Dispatchable
// GUID:      {001000AF-3DEF-0911-10B6-DC5BA692C858}
// *********************************************************************//
  _DIActiveHomeEvents = dispinterface
    ['{001000AF-3DEF-0911-10B6-DC5BA692C858}']
    procedure RecvAction(bszAction: OleVariant; bszParm1: OleVariant; bszParm2: OleVariant; 
                         bszParm3: OleVariant; bszParm4: OleVariant; bszParm5: OleVariant; 
                         bszReserved: OleVariant); dispid 0;
  end;

// *********************************************************************//
// Interface: IActiveHome
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {001000AF-3DEF-0910-10B6-DC5BA692C858}
// *********************************************************************//
  IActiveHome = interface(IDispatch)
    ['{001000AF-3DEF-0910-10B6-DC5BA692C858}']
    function SendAction(bszAction: OleVariant; bstrParam: OleVariant; vReserved1: OleVariant; 
                        vReserved2: OleVariant): OleVariant; safecall;
    procedure Set_OnRecvAction(const Param1: IDispatch); safecall;
    procedure EnumerateInterfaces(var pCount: OleVariant); safecall;
    procedure GetInterfaceName(var pInterfaceName: OleVariant); safecall;
    property OnRecvAction: IDispatch write Set_OnRecvAction;
  end;

// *********************************************************************//
// DispIntf:  IActiveHomeDisp
// Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
// GUID:      {001000AF-3DEF-0910-10B6-DC5BA692C858}
// *********************************************************************//
  IActiveHomeDisp = dispinterface
    ['{001000AF-3DEF-0910-10B6-DC5BA692C858}']
    function SendAction(bszAction: OleVariant; bstrParam: OleVariant; vReserved1: OleVariant; 
                        vReserved2: OleVariant): OleVariant; dispid 0;
    property OnRecvAction: IDispatch writeonly dispid 1;
    procedure EnumerateInterfaces(var pCount: OleVariant); dispid 2;
    procedure GetInterfaceName(var pInterfaceName: OleVariant); dispid 3;
  end;


// *********************************************************************//
// OLE Control Proxy class declaration
// Control Name     : TActiveHome
// Help String      : ActiveHome Class
// Default Interface: IActiveHome
// Def. Intf. DISP? : No
// Event   Interface: _DIActiveHomeEvents
// TypeFlags        : (2) CanCreate
// *********************************************************************//
  TActiveHomeRecvAction = procedure(ASender: TObject; bszAction: OleVariant; bszParm1: OleVariant; 
                                                      bszParm2: OleVariant; bszParm3: OleVariant; 
                                                      bszParm4: OleVariant; bszParm5: OleVariant; 
                                                      bszReserved: OleVariant) of object;

  TActiveHome = class(TOleControl)
  private
    FOnRecvAction: TActiveHomeRecvAction;
    FIntf: IActiveHome;
    function  GetControlInterface: IActiveHome;
  protected
    procedure CreateControl;
    procedure InitControlData; override;
    procedure Set_OnRecvAction(const Param1: IDispatch);
    procedure InvokeEvent(DispID: TDispID; var Params: TDispParams); override;
  public
    constructor Create(aOwner: TComponent); override;
    function SendAction(bszAction: OleVariant): OleVariant; overload;
    function SendAction(bszAction: OleVariant; bstrParam: OleVariant): OleVariant; overload;
    function SendAction(bszAction: OleVariant; bstrParam: OleVariant; vReserved1: OleVariant): OleVariant; overload;
    function SendAction(bszAction: OleVariant; bstrParam: OleVariant; vReserved1: OleVariant; 
                        vReserved2: OleVariant): OleVariant; overload;
    procedure EnumerateInterfaces(var pCount: OleVariant);
    procedure GetInterfaceName(var pInterfaceName: OleVariant);
    function TransceiverPresent: boolean;
    property  ControlInterface: IActiveHome read GetControlInterface;
    property  DefaultInterface: IActiveHome read GetControlInterface;
    property OnRecvAction1: IDispatch index 1 write SetIDispatchProp;
  published
    property Anchors;
    property  TabStop;
    property  Align;
    property  DragCursor;
    property  DragMode;
    property  ParentShowHint;
    property  PopupMenu;
    property  ShowHint;
    property  TabOrder;
    property  Visible default false;
    property  OnDragDrop;
    property  OnDragOver;
    property  OnEndDrag;
    property  OnEnter;
    property  OnExit;
    property  OnStartDrag;
    property OnRecvAction: TActiveHomeRecvAction read FOnRecvAction write FOnRecvAction;
  end;

procedure Register;

resourcestring
  dtlServerPage = 'ActiveX';

  dtlOcxPage = 'ActiveX';

implementation

uses ComObj;

procedure TActiveHome.InitControlData;
const
  CEventDispIDs: array [0..0] of DWORD = (
    $00000000);
  CControlData: TControlData2 = (
    ClassID: '{001000AF-2DEF-0208-10B6-DC5BA692C858}';
    EventIID: '{001000AF-3DEF-0911-10B6-DC5BA692C858}';
    EventCount: 1;
    EventDispIDs: @CEventDispIDs;
    LicenseKey: nil (*HR:$80004002*);
    Flags: $00000000;
    Version: 401);
begin
  ControlData := @CControlData;
  TControlData2(CControlData).FirstEventOfs := Cardinal(@@FOnRecvAction) - Cardinal(Self);
end;

constructor TActiveHome.Create(aOwner: TComponent); 
begin
  inherited Create(aOwner);
  visible := false;
end;  

procedure TActiveHome.CreateControl;

  procedure DoCreate;
  begin
    FIntf := IUnknown(OleObject) as IActiveHome;
  end;

begin
  if FIntf = nil then DoCreate;
end;

function TActiveHome.GetControlInterface: IActiveHome;
begin
  CreateControl;
  Result := FIntf;
end;

procedure TActiveHome.Set_OnRecvAction(const Param1: IDispatch);
begin
  DefaultInterface.Set_OnRecvAction(Param1);
end;

function TActiveHome.SendAction(bszAction: OleVariant): OleVariant;
begin
  Result := DefaultInterface.SendAction(bszAction, EmptyParam, EmptyParam, EmptyParam);
end;

function TActiveHome.SendAction(bszAction: OleVariant; bstrParam: OleVariant): OleVariant;
begin
  Result := DefaultInterface.SendAction(bszAction, bstrParam, EmptyParam, EmptyParam);
end;

function TActiveHome.SendAction(bszAction: OleVariant; bstrParam: OleVariant; vReserved1: OleVariant): OleVariant;
begin
  Result := DefaultInterface.SendAction(bszAction, bstrParam, vReserved1, EmptyParam);
end;

function TActiveHome.SendAction(bszAction: OleVariant; bstrParam: OleVariant;
                                vReserved1: OleVariant; vReserved2: OleVariant): OleVariant;
begin
  Result := DefaultInterface.SendAction(bszAction, bstrParam, vReserved1, vReserved2);
end;

procedure TActiveHome.EnumerateInterfaces(var pCount: OleVariant);
begin
  DefaultInterface.EnumerateInterfaces(pCount);
end;

procedure TActiveHome.GetInterfaceName(var pInterfaceName: OleVariant);
begin
  DefaultInterface.GetInterfaceName(pInterfaceName);
end;

procedure TActiveHome.InvokeEvent(DispID: TDispID; var Params: TDispParams);
begin
  if Params.cArgs=7 then
    if Assigned(FOnRecvAction) then
      FOnRecvAction(Self,OleVariant(Params.rgvarg[6]),OleVariant(Params.rgvarg[5]),
      OleVariant(Params.rgvarg[4]),OleVariant(Params.rgvarg[3]),
      OleVariant(Params.rgvarg[2]),OleVariant(Params.rgvarg[1]),
      OleVariant(Params.rgvarg[1]));
end;

function TActiveHome.TransceiverPresent: boolean;
var
  res: OleVariant;
begin
  res := SendAction('queryplc', 'a1 on');
  result := res <> -1;
end;

procedure Register;
begin
  RegisterComponents(dtlOcxPage, [TActiveHome]);
end;

end.
