Advanced Options in Active X Libraries

I am creating an ActiveX library in Delphi in which a specific object has a DevelopmentCount property with a single type date parameter. Internally, the getter property calls a similar function on a regular Delphi object, where a single parameter is optional (this last factor may not be relevant).

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

We switched to Delphi 2009 (used it for 6 months or more). When the same library is compiled with Delphi 2009, the end user, a single parameter of the DevelopmentCount property is no longer optional.

My question is how to make this option optional with Delphi 2009.

+4
source share
1 answer

To add a default parameter (called an optional parameter in VBA) in the COM library, you need to set the parameter flag in the type library editor. Click on the modifier column, then the button for the corresponding parameter. Check the box next to "Use default value" and place the default value in the provided edit box.

Now for the problem. In Delphi 2009, there is an error in the type library editor that tries to write the date to the ridl file as a string. The editor should actually convert this to an integer. This does not compile. Fortunately, the ridl file is a string file and can be edited. So this is what you will see in the ridl file

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

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

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

Now the dll will compile and the default value will be applied.

Please note: if you open the type library in Delphi, it will replace the integer with the date string, and you will not be able to compile it, so you will have to continue changing it. I do not know if this was fixed in Delphi 2010.

+3
source

All Articles