Board index » delphi » Events in a COMObject

Events in a COMObject


2003-09-10 12:52:47 AM
delphi251
Dears
I need to build a structure like this description.
I want build an COMObject and to published one (or more) events
(OnSomething). Inside of object's procedures (AnyMethod) I intend to perfom
a test and call this event (like "if event <>NIL then call event).
In a Client (a .exe Delphi or VB(Visual Basic) or Java or C++ or C# or ...) I will
instanciate this object, to build a function (MyFunction with a ShowMessage
for example), assign this function (MyFunction) to object event to, when I
to invoke the method (AnyMethod) it will execute and call the function in
the client (the function with the ShowMessage).
How to do this ?
Could someone send me an example or link or ... ?
thanks ...
Ex. Like this
COMObject (Server)
type
TEvent = class(xxx)
private
public
private
protected
{ Protected declarations }
procedure AnyMethod; safecall;
procedure OnSomethig;
end;
...
procedure TEvento.AnyMethod;
begin
for i := 0 to 1000 do
if ((i mod 100) = 0) then
if (Assigned(OnSomethig) <>NIL)
OnSomethig;
end;
----------------------------------------------------------------------------
----------------
EXE Client (Delphi, VB, Java, C++, C#, etc)
...
function MyFunction()
begin
ShowMessage('XXXXXXXXXXXXXXXXXXXXXXXXXX');
end
procedure ClickDeUmbotão()
begin
obj := Instanciate the COMObject;
obj.OnSomethig:= MyFunction; //Assign my function to event on COMObject
obj.AnyMethod();
end;
* XXXX@XXXXX.COM
 
 

Re:Events in a COMObject

To clear out the general issues of interfacing, you should create the ocx
control from any vcl class. This will give you an idea on how it actually
works. To do that goto File | New | Other | ActiveX | ActiveX control and
choose e.g. TPanel descendant. The wizard will build a working activeX with
events. Continuing from there on will be much easier. Search the "eventsink"
on google.
"Sergio Martins Vieira" <XXXX@XXXXX.COM>writes
Quote
Dears

I need to build a structure like this description.
I want build an COMObject and to published one (or more) events
(OnSomething). Inside of object's procedures (AnyMethod) I intend to
perfom
a test and call this event (like "if event <>NIL then call event).

In a Client (a .exe Delphi or VB(Visual Basic) or Java or C++ or C# or ...) I will
instanciate this object, to build a function (MyFunction with a
ShowMessage
for example), assign this function (MyFunction) to object event to, when I
to invoke the method (AnyMethod) it will execute and call the function in
the client (the function with the ShowMessage).

How to do this ?
Could someone send me an example or link or ... ?
thanks ...

Ex. Like this

COMObject (Server)

type
TEvent = class(xxx)
private
public
private
protected
{ Protected declarations }
procedure AnyMethod; safecall;
procedure OnSomethig;
end;
...

procedure TEvento.AnyMethod;
begin
for i := 0 to 1000 do
if ((i mod 100) = 0) then
if (Assigned(OnSomethig) <>NIL)
OnSomethig;
end;

--------------------------------------------------------------------------