Documentos de Académico
Documentos de Profesional
Documentos de Cultura
By Kris Golko
I recall the day when I saw Delphi 3 presented for the first time. I remember it as if it was yesterday. The presenter was so excited about ActiveX control creation but the audience didnt seem very interested in this subject. It looked so far away from the development problems of my experience. Now I work in a mixed Delphi/C++ environment and creating ActiveX controls in Delphi and handing them over to the C++ guys is an ideal solution. I can say now that it really can be done, but there are some limitations and some things you should know before you start.
Delphi versions
ActiveX control creation was introduced with Delphi 3. The Inprise development team did a terrific job here (apparently) to no avail, as I suspect that only a few people tried it in those days. Delphi 4 offers vital improvements in this area. Delphi 5 offers just a few improvements over Delphi 4, but Ive heard complaints from Delphi 4 users about the stability of the Type Library Editor, so Ive been using Delphi 5 and I would recommend it (at least if somebody is interested in ActiveX stuff).
Before you use your ActiveX control, some manual changes may be required, because some properties, events or methods might not have been translated by the wizard. You use the Type Library Editor to do this: one way to invoke it is to select View|Type library from the main menu.
Editor, and you have to change manually the code of the implementation unit. Take a close look at the implementation unit to figure out how Delphi does it and try to mimic it. As Ive mentioned before, you can easily make a mistake. When you have successfully recompiled the control after changing its type library, you possibly need to reregister it and its likely that youll need to import it again into your development tool. If you use it with Delphi, you have to remove the control from the component palette and import it again (ignoring warnings about overridden units). Be aware that changing even a single line of code may result in repeating the entire sequence.
How to use it
When you have finally compiled the control successfully, you need to register it to the system (Windows Registry). You can do it from the Delphi IDE Run|Register ActiveX Server, or using TRegSvr.exe utility bundled with Delphi, or regsvr32.exe bundled with MS Windows. Once your control is registered, you can test it in a development tool, like Visual Basic, Visual C++, C++Builder and, of course, Delphi. To use it with Delphi, you need to install it on a component palette (you can do it by selecting Component|Import ActiveX Control). Delphi will place the control on the ActiveX tab and will translate the controls type library (stored as a resource in the controls OCX file) into an Object Pascal unit. This Pascal unit will be placed by default in the imports directory (something like \Delphi5\Imports). Note that, although the unit is also called CONTROLNAME_TLB and also contains the same information, this is a completely different unit. It is not subject to change: if the control has changed you need to uninstall it and reimport it to ensure the changes are reflected.
Final thoughts
ActiveX controls can really be created by Delphi, although with a little bit of drudgery Wizards provide simple solutions for a start, but you have to find your own way of understanding the complexities of COM technologies. Working with COM in Delphi can be a good preparation for working with CORBA. These two have a lot in common, especially in Delphi.
Changes
One of the biggest disadvantages of ActiveX control creation in Delphi is making changes. Its easy if you dont have to change the type library; just change the VCL component code and recompile everything. If you want to make changes to the type library, you have to be absolutely sure you know what youre doing. Change the type library using Type Library
Kris Golko is an independent Delphi and JBuilder consultant. He holds the title of Certified Delphi 4 Client/ Server Suite Consultant. You can reach him on krzysztofgolko@yahoo.com.