Friday, March 20, 2009

Little warning

If you’re ever going to write a custom invokable variant read the following, otherwise just skip this post. I will not detail on how to create a custom invokable variant type (that is a matter for another post), but simply give an advice related to how function and procedure calls should be treated.

When implementing the DoProcedure and DoFunction methods of your custom proxy class (the one derived from TInvokeableVariantType) be sure to take into account the fact that the Arguments parameter may contain one element even though the caller did not pass any. This little “anomaly” (call it as you like) happens because you can call a method in Delphi using the Pascal style or C style syntax:

{ pascal style syntax }

{ C-style syntax }

In the first case, everything works as expected. If no parameters are passed to the called function, the Arguments parameter contains zero elements. In the second case, the Arguments array contains one element of type varError, even though you did not pass any real parameters.

Make sure your code takes this case into account, otherwise obscure errors may crawl in later.

No comments: