Com/DCom
Now, on to DCOM. I've written a 3-tier distributed RDBMS app. using D3's new Remote Data Modules. I had to add some of my own interfaces and methods to my remote data module in order to support custom SQL queries from the client. (Was that necessary?) Thus far, it all works well, and the best part: My entire client application can be distributed as 2 files! No BDE! No RDBMS client! No configuration! Cool, huh? The two files are my .exe, and 'dbclient.dll'.
My initial tests show this sytem to be somewhat slower than the 2-tier method, but I've only been coding DCOM for 2 days, so I'm hoping to find some ways to speed things up. The slowdown may also be that my ORB is running on my heavily over-loaded development machine.
Has anyone else been developing DCOM objects? I'd like to start a thread here about using Delphi for distributed app development. I'll be developing several enterprise-level distributed applications in the coming months. Would anyone here object to my posting occasional notes about what tricks/nuances I discover on the way?
Here's a sample:
Exporting DB components from Remote Data Modules
After you've created an app. and used New->Remote Data Module to create a data module for your application server, you need to export whatever TDataSet-derived components or the TProviders you created for them. To do this, just right-click on them, and there will be a menu option for exporting from your data module.
Adding your own methods to Remote Data Modules
There are two ways to do this. If you right-click on the source window while viewing the remote data module's source, there will be an option called Add to Interface. This is a mini-wizard that lets you type in a procedure, function, or property declaration. It helps you along by prompting you with helpful hints. Don't forget that you can't use just any data types for your parameters. OLE/COM/DCOM/ActiveX/Whatever only supports a subset of the data types in Delphi. (eg. Use WideString instead of String) Check in Help under 'types:type libraries' for a complete list.
Once you've gone through the wizard, Delphi puts your cursor in the right spot to fill in code for your new method.
The second way of doing this involves using the Type Library Editor (on the menu under View->Type Library). I suggest using this if you have lots of methods to add. You can add them all here, then insert the code later. Unlike Delphi-create Event-handling headers, these method headers won't go away if you leave them blank and save your code.
To access your own methods from a Remote Data Module (or other COM object)
The only way I've discovered so far is to use the TRemoteServer (Data Access page) component. Set the computer name and the server name. Then call your methods like this:
MyDataModule.MyRemoteServer.AppServer.MyCustomMethod( myParam, myParam2 );
Problem with Adding your own methods with interfaces in a type library Every method I've added to my Remote Data Module via new interfaces has had a strange problem. After creating my new interfaces, coding, saving, closing the project, and coming back, Delphi will sometimes add the 'const' keyword to the parameter lists of my afformentioned new interfaces. But Delphi -doesn't- update the parameter lists in my remote data module code, so when I compile this previously-accepted project, the compiler complains about conflicting method declarations. I have to manually add the 'const' keyword to the data module's method declarations and definitions. Then it will work fine. Once the 'const' keyword is in there, Delphi seems to leave it alone. At least, it hasn't pulled that trick on my since I added 'const' to all my method's parameter lists.
This is going to be a problem for methods that need to be able to modify their parameters. Does DCOM not support that? Any ideas?