Hi Guys,
I've been working with VB6 and ADO for awhile now and only recently, decided to give Delphi a try. I've created some ActiveX DLLs in VB6 and have been successful in accessing the objects contained within them using Delphi code(using the OLEVariant/CreateOLEObject technique).
If however, I create an ActiveX Library project in Delphi, create an object(class), compile and register it.. I don't seem to be able to access them in VB or Delphi. Below is the simple test code I'm using.
Is there something wrong with the way I've created my Library ? Is there something I'm missing or not declaring ?
And also can anyone suggest any Delphi books which might be useful.
Thanks in advance.
WB
{ DLL CODE }
library MyDLL;
uses
Classes,
ComServ,
SysUtils,
type
TMyClass = class
private
MyName : String;
MyAge : Integer;
public
constructor Create;
function DoAge(const MultiplyBy : Integer): String; safecall;
published
property Name : String read MyName write MyName;
property Age : Integer read MyAge write MyAge;
end;
{ ----------------- }
constructor TMyClass.Create;
begin
MyName := '';
MyAge := 0;
end;
function TMyClass.DoAge(const MultiplyBy : Integer): String; safecall;
begin
Result := IntToStr(MyAge * MultiplyBy);
end;
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.RES}
begin
end.
{ ----------------- }
{ TEST PROG CODE }
uses ComObj;
{ Contained in a button click event }
var
MyObj : OLEVariant;
begin
MyObj := CreateOLEObject('MyDLL.TMyClass');
MyObj.Create;
MyObj.Name('WB');
MyObj.Age(20);
ShowMessage(MyObj.DoAge(20));
end;
I've been working with VB6 and ADO for awhile now and only recently, decided to give Delphi a try. I've created some ActiveX DLLs in VB6 and have been successful in accessing the objects contained within them using Delphi code(using the OLEVariant/CreateOLEObject technique).
If however, I create an ActiveX Library project in Delphi, create an object(class), compile and register it.. I don't seem to be able to access them in VB or Delphi. Below is the simple test code I'm using.
Is there something wrong with the way I've created my Library ? Is there something I'm missing or not declaring ?
And also can anyone suggest any Delphi books which might be useful.
Thanks in advance.
WB
{ DLL CODE }
library MyDLL;
uses
Classes,
ComServ,
SysUtils,
type
TMyClass = class
private
MyName : String;
MyAge : Integer;
public
constructor Create;
function DoAge(const MultiplyBy : Integer): String; safecall;
published
property Name : String read MyName write MyName;
property Age : Integer read MyAge write MyAge;
end;
{ ----------------- }
constructor TMyClass.Create;
begin
MyName := '';
MyAge := 0;
end;
function TMyClass.DoAge(const MultiplyBy : Integer): String; safecall;
begin
Result := IntToStr(MyAge * MultiplyBy);
end;
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.RES}
begin
end.
{ ----------------- }
{ TEST PROG CODE }
uses ComObj;
{ Contained in a button click event }
var
MyObj : OLEVariant;
begin
MyObj := CreateOLEObject('MyDLL.TMyClass');
MyObj.Create;
MyObj.Name('WB');
MyObj.Age(20);
ShowMessage(MyObj.DoAge(20));
end;