Table of Contents
- X10 Forum Help
- What Is a Type Library?
- Importing the ActiveHome Type Library in Delphi 2010
- Importing the ActiveHome Type Library in Delphi 7
X10 Forum Help
As we shall see, ahscript.dll has only two methods of interest to us. But we need to know the entry points for these functions, their parameters and so on. One can look at the AHSDK's examples to try to do this, but Federico Morales provides the best clue about how to go about it with Delphi on the X10 forum:
the right way is: in the menu go
to [project] then import type library and choose the component :-)
|
And a few months later dbaxter adds a bit more information with a warning about the receive method that turns out to be correct:
You need to install it as an
ActiveX component. Then it will appear on your tool pallet and you can
drop it on your project form. You probably want to make it invisible.
Then it's as simple as:
procedure TForm1.DoPower(Address: string; PwrOn: boolean); var s: string; begin If PwrOn then s := Address + ' on' else s := Address + ' off'; ActiveHome1.SendAction('sendplc', s); end; The receive function that shows in the components event list is problematic, however. |
If you know how to add ActiveX components by importing a type
library then go ahead and import the ActiveHomeScript 1.0 Type Library
right now and then go directly to the next
part.
If you have never done that, then, like me, you'll find the task a bit
daunting. So I looked up some information on the Web and finally
managed to do it for the first time. Below you will find a step by step
procedure to help you. But first, what is a type library?
What Is a Type Library?
A type library is a file which contains such
information. More precisely, here is Microsoft's
definition
Type Library
A type library (.tlb) is a binary file that stores information about a COM or DCOM object's properties and methods in a form that is accessible to other applications at runtime. Using a type library, an application or browser can determine which interfaces an object supports, and invoke an object's interface methods. This can occur even if the object and client applications were written in different programming languages.
Luckily, Delphi can "import" a type library. This consists essentially of
reading the information and creating a Delphi unit which will contain a
class defining ahscript's only object and its
methods.
Below are the steps required to import a type library, first in Delphi2010 and after in Delphi 7. Just a reminder: either the AHSDK or the ActiveHomePro software must be installed. During either of these installations, ahscript.dll is registered (added under the appropriate key in the Windows registry) and that is how Delphi can find the type library.
Importing the ActiveHome Type Library in Delphi 2010
- Start Delphi 2010.
- Click on Import Component... in the Component menu :
- Check Import a Type Library and click on Next:
- Find and select the ActiveHomeScript
1.0 Type Library and then click Next:

- Choose a Palette
Page where the component will be made available (here
ActiveX), make sure that the check box Generate
Component Wrappers is checked and then click on Next.
- Check Install
to New Package in the next window and click on Finish:
- In the New Package window, add a Package
name and a Description.
For the package name, I wrote
x10Server, Delphi expanded it toC:\Program Files (x86)\Embarcadero\RAD Studio\7.0\OCX\Servers\x10Server.dpk. The description is up to you. Then click Finish.
- The unit
ActiveHomeScriptLib_TLBis created, saved in the Import folder{userdocs}\RAD Studio\7.0\Importsand opened in Delphi's source editor. An information dialogue is then displayed telling you that all the work has been done for you! Click on OK:
If you scroll through the source, you will find a number of constants
and type declarations ending with the definition of a single class
TActiveHome = class(TOleControl)
and a Register procedure. Pay attention to
the warning. We will come back to that later.
Actually Delphi did quite a bit more than
create the ActiveHomeScriptLib_TLB.pas file.
It created a dcr (a bitmap to be shown on the
component palette)
in the same folder. In addition to the file x10Server.dpk
the files x10Server.res and x10Server.dproj
were created in the folder C:\Program Files
(x86)\Embarcadero\RAD Studio\7.0\OCX\Servers\. And as
promised a bpl file was created and installed in Delphi.

If you have Delphi2010 you can now move on to the next page to see how the component can be used. If you have Delphi 7 than you can see below how to import the type library. If you have a different version of Delphi, hopefully these two examples will guide you and you will be able to import the type library.
Importing the ActiveHome Type Library in Delphi 7
Again, Delphi 7 does most of the leg work for us, albeit in a slightly different way.
- Start Delphi 7
- Click on Import
Type Library in the Project
menu as shown below (while I use a French version of Delphi 7, I trust that the image below should tell you where these
choices live on the IDE.)

- Select the ActiveHomeScript
1.0 Type Library (Version 1.0) and then choose a Palette
Page where the component will be made available (here
ActiveX), make sure that the check box Generate
Component Wrappers is checked and then
click on
the Install
button

- In the New Package tab, add File
(package name) and a Description.
For the package name, I wrote
x10Server. The description is up to you. Then click OK.
- Delphi will then warn you that it is about to build the
package. Click on Yes.

- Delphi now tells you that it has built the
package. The unit
ActiveHomeScriptLib_TLB.pasand the bitmapActiveHomeScriptLib_TLB.dcrwere created and saved in the Import folderC:\Program Files (x86)\Borland\Delphi7\Imports\. Click on OK.
- Do not forget to save changes when you close the
x10Server.dpk window; click on Yes.
Dcp and bpl files will also be constructed and save in Delphi's Bpl folder:
while the package source and associated files will be place in Delphi's lib folder:C:\Program Files (x86)\Borland\Delphi7\Projects\Bpl\x10Server.bpl
C:\Program Files (x86)\Borland\Delphi7\Projects\Bpl\x10Server.dcp
C:\Program Files (x86)\Borland\Delphi7\Lib\x10Server.cfg
C:\Program Files (x86)\Borland\Delphi7\Lib\x10Server.dof
C:\Program Files (x86)\Borland\Delphi7\Lib\x10Server.dpk
C:\Program Files (x86)\Borland\Delphi7\Lib\x10Server.res
There is only one difference in the two versions of ActiveHomeScriptLib_TLB.pas generated
by Delphi 7 and Delphi 2010. Just before the reserved word interface,
there are 5 compiler directives inserted by Delphi 2010, and
only 4 by Delphi 7:

Introduction