Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveX DLLs in Delphi 4

Status
Not open for further replies.

wildbash

Programmer
Nov 16, 2001
16
AU
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;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top