Hope this helps..

First we need an abstract class which your application uses to 'know' how to use the class in the DLL..

[pascal]
type
TBaseTest = class
public
function GetValue : Integer; virtual; abstract;
end;
[/pascal]

This is pretty useless as a class, returning the number 1234 through a DLL has no use whatsoever, but its the principle

You only have to declare the public section in our abstract class, and in it all procs/funcs must be virtual and abstract. Public variables are declared in the normal way, private variables don't have to be declared.

Next, in the DLL, we create the implementation of this class, eg:

[pascal]
type
TBaseTestImp = class(TBaseTest)
private
DummyValue : integer;
public
function GetValue: integer; override;
end;
[/pascal]

and the GetValue function...

[pascal]
function TBaseTestImp.GetValue : integer;
begin
Result := 1234;
end;
[/pascal]

Now, create another unit of the DLL and create this function..

[pascal]
function CreateNewObject : TBaseTest;
begin
CreateNewObject:= TBaseTestImp.Create;
end;
[/pascal]

This creates a new instance and returns its reference. This function must be added to the exports list in the DLL.

Compile the DLL, and now on to the EXE

[pascal]
procedure TForm1.FormCreate(Sender : TObject);
var
a : TBaseTest;
begin
a := CreateNewObject;
ShowMessage('The number is :' + IntToStr(a.GetValue));
a.Free;
end;
[/pascal]

and for completeness, the DLL function declaration

[pascal]
function CreateNewObject : TBaseTest; stdcall; external 'MyDll.dll';
[/pascal]

.Zanthos