Auto-generate implementation wrappers for interface/coclasses

This article explains a quick and simple method of allowing Delphi to automatically generate implementation wrappers for each interface/coclass you add to a type library.

If you've ever created an Active-X library before and have added an Automation Object, you've probably noticed that Delphi was nice enough to create a unit containing an implementation wrapper, using TAutoObject and your initial interface as the base.

If, however, you use the type library editor to add subsequent interfaces and coclasses, you've probably noticed that Delphi didn't create wrappers for these newly created interfaces for you.

I've seen people copy and paste code from the initial unit that Delphi generated for them into new units, replace respective GUID's, and write the wrapper themselves. I've also seen people go so far as to write the entire implementation wrapper themselves by hand. Still others sit, frustrated, wondering exactly what they did wrong.

Well, the answer is simple. When you want to add a new interface / coclass to your type library, simply insert it via File -> New -> Active-X -> Automation Object. This will NOT create a new project; that's what File -> New -> Active-X -> Active-X DLL does. By using the New -> Automation Object option, Delphi will not only insert your new interface and coclass (and optionally, a dispinterface) into your type library, but it will also generate the implementation wrapper for you.

Now, when you insert additional methods and properties and click Refresh, the implementation wrapper unit generated by Delphi will automatically be updated to reflect your changes. No more adding method declarations by hand!

Also, keep in mind that when you name your Automation Object, do not prefix your object with an I or a T. Delphi will do this for you. An object name of "MyNewObject" will result in an IMyNewObject interface and a MyNewObject coclass being created in the type library. If you enable event support, the dispinterface will be named MyNewObjectEvents.


Jason Plackey

Vice President of Business Development

Raven2K Integrated Solutions

[email protected]


Share this article!

Follow us!

Find more helpful articles: