views:

224

answers:

2

I am creating an ActiveX library in Delphi in which a particular object has a property called DevelopmentCount with a single parameter of type date. Internally the property getter calls a similarly named function on a normal Delphi object where the single parameter is optional (this last factor may be irrelevant).

When we compile this library in Delphi 2006 to the end user (using Excel VBA) it appears that the single parameter of the DevelopmentCount propery is optional.

We have moved over to Delphi 2009 (have been using it for 6 months or more). When the same library is compiled with Delphi 2009, to the end user, the single parameter of the DevelopmentCount property is no longer optional.

My question is, how can I make this parameter appear to be optional with Delphi 2009.

+3  A: 

To add a Default Parameter (called an optional parameter in VBA) in a COM Library, you need to set the parameter flag in the type library editor. Click on the modifier column, then on the button of the parameter in question. Tick the has default value check box, and put a default value in the supplied edit box.

Now for the problem. In Delphi 2009, there is a bug in the type library editor, which attempts to write the date out to the ridl file as a string. The editor should in fact convert this to a integer. This will not compile. Luckily, the ridl file, is a string file, and can be edited. So this is what you'll see in the ridl file

HRESULT _stdcall DevelopmentCount([in, defaultvalue(29/12/1899)] DATE);

change that date to an integer (note 30/12/1899 is 0)

HRESULT _stdcall DevelopmentCount([in, defaultvalue(-1)] DATE);

The dll will now compile, and the default value applied.

Note that if you open up the type library in Delphi, it will replace the integer with the date string, and again you will not be able to compile, so you'll have to keep changing it back. I don't know whether this has been fixed in Delphi 2010.

Steve