views:

120

answers:

2

We’re rewriting a calculation core from scratch in Delphi, and we’re looking for ways to let other people write code against it.

Automation seems a fairly safe way to get this done. One use we’re thinking of is making it available to VBA/Office, and also generating a .NET assembly (based on the Automation object, that's easy).

But the code should still be easy to use from Delphi, since we’ll be writing our (desktop) UI with that.

Now I’ve been looking into creating an Automation server in Delphi, and it looks like quite a hassle to have to design the components in the Type Library wizard, and then generate the base code.

The calculations we’re having to implement are described in official rules and regulations that are still not ratified, and so could still change before we’re done — they very probably will, perhaps quite extensively. Waiting for the final version is not an option.

An alternative way could be to finish the entire object model first, and write a separate Automation server which only describes the top-level object, switch $METHODINFO ON, and use TObjectDispatch to return all the subordinate objects. As I see it, that would entail having to write wrappers to return the objects by IDispatch interface. Since there's over a 100 different classes in there, that doesn’t look like an attractive option. Edit: TObjectDispatch is smart enough to wrap any objects returned by properties and methods as well; so only the top object(s) would need to be wrapped. Lack of a complete type library does mean only late-binding is possible, however.

Is there an other, easier (read: hassle-free) way to write a COM-accessible object model in Delphi?

+2  A: 

You don't have to use the type library designer. You can write or generate (e.g. from RTTI of your Delphi classes) a .ridl file and add it to your Automation library project.

TOndrej
So... write the Delphi code, use RTTI to generate a .ridl file, then update the Delphi code with the proper interfaces, GUIDs and stuff?Are there any tools that can do this?
Martijn
The .ridl should already contain GUIDs and interface declarations. You could let Delphi generate a Delphi unit containing implementation stubs (like with type library designer), then fill in the implementations by delegating property/method calls to your original classes.I'm not aware of any such tools available but I haven't searched for them.
TOndrej
A: 

Generating interface description from RTTI is a great idea! After you have your interfaces generated you can generate a delphi unit from them and implementing in your classes. Of course the majority are implemented already since you have generated the interfaces from those classes after all. The late binding resolution can be done after that by hand using RTTI and implementing IDispatch and IDispatchEx in a common baseclass of the scriptable classes.

r4w8173