I'm trying to make an app with event/methods/procedures to be taken from a third party application.
This app needs to be an active X
.
I have an working example on VB.NET
and I need to make a the same on Delphi.
The vb.net
Unit start with:
<ComClass(InteropUserControl.ClassId, InteropUserControl.InterfaceId, InteropUserControl.EventsId)> _
Public Class InteropUserControl
Is this completely necessary on DELPHI? is this only for register a COM class on Windows?
Also, the function used is:
Public Event msgPlugIn(ByRef Msg As String, ByRef MsgResponse As String)
And it's called later:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Msg As String
Dim Response As String = ""
Msg = "<ID><infoRequest/></ID>"
RaiseEvent MsgPlugIn(Msg, Response)
rtb1.Text = Response
//rtb1 is a regular label
End Sub
is this an Onclick
of a regular Button?
I need to get this done in Delphi, but I try everything, Automation Object
, COM Object
..but the third party app doesn't make anything.
NEW INFO:
I made an Active Library and add a COM OBJECT and create a procedure:
unit DataExchange;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, ActiveX, Classes, ComObj, TEST_2_TLB, StdVcl, dialogs;
type
TDataExchange = class(TTypedComObject, IDataExchange)
protected
procedure MENSAJE(out DATA: WideString); stdcall;
end;
implementation
uses ComServ;
procedure TDataExchange.MENSAJE(out DATA: WideString);
begin
showmessage(DATA);
end;
initialization
TTypedComObjectFactory.Create(ComServer, TDataExchange, Class_DataExchange,
ciMultiInstance, tmApartment);
end.
I create a Client to read this dll calling it this way:
procedure MENSAJE(out DATA: WideString); external 'TEST__2.ocx';
procedure TForm2.btn1Click(Sender: TObject);
var
texto : WideString;
begin
texto := edt1.Text;
MENSAJE (texto);
end;
Then when I execute the client an error shows up:
the Procedure entry point
MENSAJEcould not be located in the dynamic library TEST__2.ocx
It Works if I create this procedure directly on the library unit, Like this:
library TEST__2;
uses
ComServ,dialogs,
TEST_2_TLB in 'TEST_2_TLB.pas',
MAINFORM in 'MAINFORM.pas' {SuperActiveFORM: TActiveForm} {SuperActiveFORM: CoClass},
DataExchange in 'DataExchange.pas' {DataExchange: CoClass};
{$E ocx}
procedure MENSAJE(out DATA: WideString); stdcall;
begin
showmessage(DATA);
end;
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer,
DllInstall,
Mensaje;
{$R *.TLB}
{$R *.RES}
begin
end.
The thing is that if I create the procedure in the unit, I made it writing it. In the COM OBJECT I made it thru the ridl file, adding a method to the interface.
A COM Object inside of an ActiveX Library is the correct approach to expose functionality to outside apps. Your test client failed because you did not have it load the COM object at all, you tried to access a standalone function, but there really is none. You have to register your compiled DLL using regsvr32.exe, and then a client app can use CoCreateInstance/Ex()
to instantiate the COM object when needed, call methods on it, and assign event handlers to it.
One of the better COM tutorials for Delphi (and C++Builder) is http://www.techvanguards.com, IMHO.