On Mon, 27 May 1996 13:15:10 -0300, "Daniel Polistchuck"
Quote
<dan...@pobox.com> wrote:
>Does anyone have any experience in writing
>Delphi2 extensions using the OpenTools API?
yes.
Quote
>I have already taken a look at the example, but
>since it is sparsely commented, the real philosophy
>behind the scene tends to be a little obscure.
>I already understood that Delphi 2 seems to export
>classes to be used by its extensions, something
>like - but simpler than- OLE Automation. But
>the actual class hierarchy of this API is not clear.
>Does anyone have a clearer and more specific view
>than mine? Is there any good documentation about
>this subject?
There will be books appearing in the near future that should describe
the Open Tools API a little better. Until then, here is a capsule
summary:
First of all, read the source files and the comments carefully.
Believe it or not, they are mostly accurate.
There are two kinds of classes in the API: Interfaces and Notifiers.
An interface is an abstract interface class. You don't know or care
what concrete class implements the interface. All that matters is that
you call a method that returns an interface object. You then use the
interface object and then free it.
A notifier is an abstract interface class, from which you must derived
your own, concrete class. There are two notifier classes:
TIModuleNotifier and TIAddInNotifier. You use a notifier by creating
an instance of your class and calling a register method. When you are
done, remember to unregister the notifier before freeing it.
Everything starts with the TIToolServices class. Delphi gives you an
instances of TIToolServices when you register the expert. (OK, there's
a third kind of class, the expert interface. You must define a
concrete derived class, and register it in the expert initialization
procedure.) There are other ways to get the ToolServices object, but
save that for the advanced Open Tools lesson...
You do not free the TIToolServices object when you are done using it.
You do not free the expert interface object. Delphi does that for you.
Every other object that Delphi returns from an Open Tools API method
must be freed.
From the TIToolServices object, you can obtain a module interface
(TIModuleInterface). The module interface tells you about a file. From
the module interface, you can get an editor interface (for the source
file) or a form interface (for the form editor).
The editor interface lets you query the views, so you can learn the
cursor position, etc. You can also read a source file and make changes
to it, using the edit reader and edit writer. These can be a little
tricky to use. (If you have specific questions, post them here, and
someone can probably answer them.)
A form interface lets you learn about the components on a form, and
the components' properties. Remember that the component and form
instances are in the component library DLL, but the expert is in its
own DLL. Because each DLL is compiled separately, it is possible for
the two DLLs to have different versions of a class's Virtual Method
Table. (Say, an update to Delphi 2 changes the VMT of TComponent. For
any one of a number of reasons, the expert DLL is not updated. There
is no way for the expert DLL to know that it is using a different
version of the VMT than the component library. The result would
probably be a {*word*193} crash.)
To make it easier, the TIComponentInterface class defines methods for
accessing the properties of a component. Always check the type of a
property before getting or setting its value. Just because a property
is named Name does not guarantee that it is a string. A naive
programmer can redefine properties, and the property interface in
TIComponentInterface is NOT type safe.
The module interface for the project module (.DPR) also lets you add
or change the resources. By default, Delphi manages the MAINICON
resource, which is the application icon, but you can add resources to
the project's resource file.
The Tool Services object lets you access Delphi's menu bar, and add
new menu items. When you add a menu item, you can define the state of
the menu item, add an OnClick handler, etc. You cannot modify any of
the predefined menu items.
It is a lot to digest, but once you understand how it works, the Open
Tools API is actually quite simple and easy to use.
--
Ray Lischner li...@tempest-sw.com
Tempest Software, Corvallis, Oregon, USA http://www.tempest-sw.com