Joe Caverly Guest
|
Posted: Fri Apr 16, 2004 1:53 pm Post subject: Automation Server won't work as early-bound |
|
|
Hi,
I used Delphi Desktop 2.0 to develop an Automation Server called
JLCMATH.DLL
The code is as follows;
JLCMATH.DPR
SNIP--------
library JLCMath;
uses
SysUtils,
Classes,
OLEAuto,
Unit1 in 'Unit1.pas';
exports
DllGetClassObject, DllCanUnloadNow, DllRegisterServer,
DllUnregisterServer;
begin
end.
UNIT1.PAS
SNIP--------
unit Unit1;
interface
uses
OleAuto;
type
Math = class(TAutoObject)
private
{ Private declarations }
automated
{ Automated declarations }
function PricePerPound(PricePerKg : double) : double;
function Get : Variant;
end;
implementation
function Math.Get : Variant;
begin
Get := 'JLC';
end;
function Math.PricePerPound(PricePerKg : double) : double;
begin
result := PricePerKg * 0.454;
end;
procedure RegisterMath;
const
AutoClassInfo: TAutoClassInfo = (
AutoClass: Math;
ProgID: 'JLCMath.Math';
ClassID: '{86647C20-8F69-11D8-9B06-0048548A983C}';
Description: 'Math Class';
Instancing: acMultiInstance);
begin
Automation.RegisterClass(AutoClassInfo);
end;
initialization
RegisterMath;
end.
SNIP------
I placed the JLCMATH.DLL file in the C:WINDOWSSYSTEM folder, and
used REGSVR32 to successfully register the Automation Server.
When I call the routines from JLCMATH.DLL in Visual Basic 5.0
Professional SP3 using the following code (late-bound);
Private Sub Form_Load()
Set JLC = CreateObject("JLCMath.Math")
Result = JLC.PricePerPound(6.59)
MsgBox Result
MsgBox JLC.Get
Set JLC = Nothing
End
End Sub
everything works fine, and I get the desired results. No problem so
far.
I would like to make the reference early-bound. So, from Visual Basic,
I select Project | References, and look for my Automation Server.
Nowhere to be found. So, I browse to the JLCMATH.DLL, and click open.
Visual Basic displays a dialog box with the message "Can't add a
reference to the specified file."
Why not?
So, I use the OLE-COM Object Viewer from Visual Studio to locate my
Automation Server. I look under Automation Objects, but it's nowhere
to be found.
I did a search of the registry, and found JLCMath.Math.
Questions. First, why does my Delphi Automation Server work as
late-bound from Visual Basic 5.0, but not early-bound from Visual
Basic 5.0? How can I make my Delphi Automation Server so that it can
be early-bound to Visual Basic 5.0?
Thanks,
Joe
|
|