RAD Studio
ContentsIndex
PreviousUpNext
Using Object Pascal or IDL Syntax

The Text page of the Type Library editor displays your type information in one of two ways:

  • Using an extension of Delphi syntax.
  • Using the Microsoft IDL.
You can select which language you want to use by changing the setting in the Environment Options dialog. Choose Tools Options, and specify either Pascal or IDL as the Language on the Type Library page of the dialog.
Note: The choice of Delphi or IDL syntax also affects the choices available on the parameters attributes page.
Like Delphi applications in general, identifiers in type libraries are case insensitive. They can be up to 255 characters long, and must begin with a letter or an underscore (_).

Delphi has been extended to allow type libraries to include attribute specifications. Attribute specifications appear enclosed in square brackets and separated by commas. Each attribute specification consists of an attribute name followed (if appropriate) by a value. 

The following table lists the attribute names and their corresponding values.  

Attribute syntax  

Attribute name 
Example 
Applies to 
aggregatable  
[aggregatable]  
typeinfo  
appobject  
[appobject]  
CoClass typeinfo  
bindable  
[bindable]  
members except CoClass members  
control  
[control]  
type library, typeinfo  
custom  
[custom '{7B5687A1-F4E9-11D1-92A8-00C04F8C8FC4}' 0]  
anything  
default  
[default]  
CoClass members  
defaultbind  
[defaultbind]  
members except CoClass members  
defaultcollection  
[defaultcollection]  
members except CoClass members  
defaultvtbl  
[defaultvtbl]  
CoClass members  
dispid  
[dispid]  
members except CoClass members  
displaybind  
[displaybind]  
members except CoClass members  
dllname  
[dllname 'Helper.dll']  
module typeinfo  
dual  
[dual]  
interface typeinfo  
helpfile  
[helpfile 'c:\help\myhelp.hlp']  
type library  
helpstringdll  
[helpstringdll 'c:\help\myhelp.dll']  
type library  
helpcontext  
[helpcontext 2005]  
anything except CoClass members and parameters  
helpstring  
[helpstring 'payroll interface']  
anything except CoClass members and parameters  
helpstringcontext  
[helpstringcontext $17]  
anything except CoClass members and parameters  
hidden  
[hidden]  
anything except parameters  
immediatebind  
[immediatebind]  
members except CoClass members  
lcid  
[lcid $324]  
type library  
licensed  
[licensed]  
type library, CoClass typeinfo  
nonbrowsable  
[nonbrowsable]  
members except CoClass members  
nonextensible  
[nonextensible]  
interface typeinfo  
oleautomation  
[oleautomation]  
interface typeinfo  
predeclid  
[predeclid]  
typeinfo  
propget  
[propget]  
members except CoClass members  
propput  
[propput]  
members except CoClass members  
propputref  
[propputref]  
members except CoClass members  
public  
[public]  
alias typeinfo  
readonly  
[readonly]  
members except CoClass members  
replaceable  
[replaceable]  
anything except CoClass members and parameters  
requestedit  
[requestedit]  
members except CoClass members  
restricted  
[restricted]  
anything except parameters  
source  
[source]  
all members  
uidefault  
[uidefault]  
members except CoClass members  
usesgetlasterror  
[usesgetlasterror]  
members except CoClass members  
uuid  
[uuid '{7B5687A1-F4E9-11D1-92A8-00C04F8C8FC4}' ]  
type library, typeinfo (required)  
vararg  
[vararg]  
members except CoClass members  
version  
[version 1.1]  
type library, typeinfo  

The Delphi syntax for declaring interface type information has the form

interfacename = interface[(baseinterface)] [attributes]
functionlist
[propertymethodlist]
end;

For example, the following text declares an interface with two methods and one property:

Interface1 = interface (IDispatch)
  [uuid '{7B5687A1-F4E9-11D1-92A8-00C04F8C8FC4}', version 1.0]
  function Calculate(optional seed:Integer=0): Integer;
  procedure Reset;
  procedure PutRange(Range: Integer) [propput, dispid $00000005]; stdcall;
  function GetRange: Integer;[propget, dispid $00000005]; stdcall;
end;

The corresponding syntax in Microsoft IDL is

[uuid '{5FD36EEF-70E5-11D1-AA62-00C04FB16F42}',version 1.0]
interface Interface1 :IDispatch
{
  long Calculate([in, optional, defaultvalue(0)] long seed);
  void Reset(void);
  [propput, id(0x00000005)] void _stdcall PutRange([in] long Value);
  [propput, id(0x00000005)] void _stdcall getRange([out, retval] long *Value);
};

The Delphi syntax for declaring dispinterface type information has the form

dispinterfacename = dispinterface [attributes]
functionlist
[propertylist]
end;

For example, the following text declares a dispinterface with the same methods and property as the previous interface:

MyDispObj = dispinterface
[uuid '{5FD36EEF-70E5-11D1-AA62-00C04FB16F42}',
  version 1.0,
  helpstring 'dispatch interface for MyObj'
  function Calculate(seed:Integer): Integer [dispid 1];
  procedure Reset [dispid 2];
  property Range: Integer [dispid 3];
end;

The corresponding syntax in Microsoft IDL is

[uuid '{5FD36EEF-70E5-11D1-AA62-00C04FB16F42}',
  version 1.0,
  helpstring "dispatch interface for MyObj"
dispinterface Interface1
{
  methods:
    [id(1)] int Calculate([in] int seed);
    [id(2)] void Reset(void);
  properties:
    [id(3)] int Value;
};

The Delphi syntax for declaring CoClass type information has the form

classname = coclass(interfacename[interfaceattributes], ...); [attributes];

For example, the following text declares a coclass for the interface IMyInt and dispinterface DmyInt:

myapp = coclass(IMyInt [source], DMyInt);
[uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
  version 1.0,
  helpstring 'A class',
  appobject]

The corresponding syntax in Microsoft IDL is

[uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
  version 1.0,
  helpstring "A class",
  appobject]
coclass myapp
{
  methods:
  [source] interface IMyInt);
  dispinterface DMyInt;
};

The Delphi syntax for declaring Enum type information has the form

enumname = ([attributes] enumlist);

For example, the following text declares an enumerated type with three values:

location = ([uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
         helpstring 'location of booth']
  Inside = 1 [helpstring 'Inside the pavillion'];
  Outside = 2 [helpstring 'Outside the pavillion'];
  Offsite = 3 [helpstring 'Not near the pavillion'];);

The corresponding syntax in Microsoft IDL is

[uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
        helpstring "location of booth"]
typedef enum
{
  [helpstring "Inside the pavillion"] Inside = 1,
  [helpstring "Outside the pavillion"] Outside = 2,
  [helpstring "Not near the pavillion"] Offsite = 3
} location;

The Delphi syntax for declaring Alias type information has the form

aliasname = basetype[attributes];

For example, the following text declares DWORD as an alias for integer:

DWORD = Integer [uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}'];

The corresponding syntax in Microsoft IDL is

[uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}'] typedef long DWORD;

The Delphi syntax for declaring Record type information has the form

recordname = record [attributes] fieldlist end;

For example, the following text declares a record:

Tasks = record [uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
                helpstring 'Task description']
  ID: Integer;
  StartDate: TDate;
  EndDate: TDate;
  Ownername: WideString;
  Subtasks: safearray of Integer;
end;

The corresponding syntax in Microsoft IDL is

[uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
        helpstring "Task description"]
typedef struct
{
  long ID;
  DATE StartDate;
  DATE EndDate;
  BSTR Ownername;
  SAFEARRAY (int) Subtasks;
} Tasks;

The Delphi syntax for declaring Union type information has the form

unionname = record [attributes]
case Integer of
  0: field1;
  1: field2;
  ...
end;

For example, the following text declares a union:

MyUnion = record [uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
                  helpstring "item description"]
case Integer of
  0: (Name: WideString);
  1: (ID: Integer);
  3: (Value: Double);
end;

The corresponding syntax in Microsoft IDL is

[uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
        helpstring "item description"]
typedef union
{
  BSTR Name;
  long ID;
  double Value;
  } MyUnion;

The Delphi syntax for declaring Module type information has the form

modulename = module constants entrypoints end;

For example, the following text declares the type information for a module:

MyModule = module [uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
                   dllname 'circle.dll']
  PI: Double = 3.14159;
  function area(radius: Double): Double [ entry 1 ]; stdcall;
  function circumference(radius: Double): Double [ entry 2 ]; stdcall;
end;

The corresponding syntax in Microsoft IDL is

[uuid '{2MD36ABF-90E3-11D1-AA75-02C04FB73F42}',
        dllname("circle.dll")]
module MyModule
{
  double PI = 3.14159;
  [entry(1)] double _stdcall area([in] double radius);
  [entry(2)] double _stdcall circumference([in] double radius);
};
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!