Adding Properties and Methods to the Type Library

From RAD Studio
Jump to: navigation, search

Go Up to Using the Type Library Editor


To add properties or methods to an interface or dispinterface

  1. Select the interface and choose either a property or method icon from the toolbar. If you are adding a property, you can click directly the property icon to create a read/write property (with both a getter and a setter), or click the down arrow to display a menu of property types. The property access method members or method member is added to the object list pane, prompting you to add a name.
  2. Type a name for the member.

The new member contains default settings on its attributes, parameters, and flags pages that you can modify to suit the member. For example, you will probably want to assign a type to a property on the attributes page. If you are adding a method, you will probably want to specify its parameters on the parameters page.

As an alternate approach, you can add properties and methods by typing directly into the text page using Delphi or IDL syntax. For example, if you are working in Delphi syntax, you can type the following property declarations into the text page of an interface:

Interface1 = interface(IDispatch)
  [ uuid '{5FD36EEF-70E5-11D1-AA62-00C04FB16F42}',
    version 1.0,
    dual,
    oleautomation ]
  function AutoSelect: Integer [propget, dispid $00000002]; safecall; // Add this
  function AutoSize: WordBool [propget, dispid $00000001]; safecall; // And this
  procedure AutoSize(Value: WordBool) [propput, dispid $00000001]; safecall; // And this
end;

If you are working in IDL, you can add the same declarations as follows:

[
   uuid(5FD36EEF-70E5-11D1-AA62-00C04FB16F42),
   version(1.0),
   dual,
   oleautomation
]
interface Interface1: IDispatch
{ // Add everything between the curly braces
[propget, id(0x00000002)]
   HRESULT _stdcall AutoSelect([out, retval] long Value );
   [propget, id(0x00000003)]
   HRESULT _stdcall AutoSize([out, retval] VARIANT_BOOL Value );
   [propput, id(0x00000003)]
   HRESULT _stdcall AutoSize([in] VARIANT_BOOL Value );
};

After you have added members to an interface using the interface text page, the members appear as separate items in the object list pane, each with its own attributes, flags, and parameters pages. You can modify each new property or method by selecting it in the object list pane and using these pages, or by making edits directly in the text page.

If the interface is associated with a CoClass that was generated by a wizard, you can tell the Type Library Editor to apply your changes to the implementation file by clicking the Refresh button on the toolbar. The Type Library Editor adds new methods to your implementation class to reflect the new members. You can then locate the new methods in implementation unit's source code and fill in their bodies to complete the implementation.

If you have the Apply Updates Dialog enabled, the Type Library Editor notifies you of all changes before updating the sources and warns you of potential problems.

See Also