Board index » delphi » VBA + Events Generated from Delphi based OLE Automation Object

VBA + Events Generated from Delphi based OLE Automation Object

Hi,

I am new to OLE Automation etc but I have managed getting code working for
"normal" methods and properties (things such as Application.Quit and
Document.Filename etc etc) but I can't figure out how to place events into
my Automation Object (things such as Application.OnClose).

I have placed a Microsoft Script Control object onto my form and can execute
code that uses my automation object, so I know I have access to the
automation object and the basics of it are working - however any attempt at
writing event handlers fail.

I have tried such online documents as Microsoft's MSDN and Binh Ly's COM
tutorial. Both have stuff about automation object events but I couldn't
figure it out.

From the documentation for both technologies involved it should be simple
but I've been playing around and just can't get it to work.

Here is how I see I am supposed to implement an event for an automation
object - say an event called OnMyEvent:

On the VBA side it should be as simple as

private sub application_onmyevent()
     .....
end sub

then again it could be

set application.onmyevent = GetRef(Name_Of_Subroutine_To_Handle_Event)

Both are shown in various places in the VBA documentation. The code should
mean that when the OnMyEvent event is fired from the automation object the
associated code in the above script subroutine will be executed.

On the Delphi side I'm lost. I've created an OLE Automation server via
Delphi's wizard and told it to include event support code.

This creates two interfaces one for methods etc and one for events. To add
an event to my automation server I add a method in the event interface? Am I
correct? The Delphi documents seems to say this is what should be done
anyway.....

Now I assume that to fire the event I call FEvents.OnMyEvent? FEvents is
part of the code generated by Delphi when event support is included and it
does have an OnMyEvent method when I add the event via the Type Editor. But
FEvents always points to NIL.

Is FEvents pointing to NIL because my VBA script isn't "sinking the event"
or is it simply that I don't know what I am doing?

Can someone please show me how to implement an automation object event in
delphi, or at least point me in the right direction?

Once I get the actual automation server part done I can go about figuring
out what code I should be writting on the script side - I'm using the divide
and conquer theory here........

Thanks,
Christopher Fairbairn.

 

Re:VBA + Events Generated from Delphi based OLE Automation Object


When you go into my EventSinkImp page, there is a DelphiSinkDemo.zip
download that shows a very simple Delphi COM server that raises an event the
way you want it.

have fun
--
Binh Ly
Need help on COM development?
http://www.techvanguards.com

Quote
Christopher Fairbairn <lgc...@es.co.nz> wrote in message

news:86unov$2nm5@bornews.borland.com...
Quote
> Hi,

> I am new to OLE Automation etc but I have managed getting code working for
> "normal" methods and properties (things such as Application.Quit and
> Document.Filename etc etc) but I can't figure out how to place events into
> my Automation Object (things such as Application.OnClose).

> I have placed a Microsoft Script Control object onto my form and can
execute
> code that uses my automation object, so I know I have access to the
> automation object and the basics of it are working - however any attempt
at
> writing event handlers fail.

> I have tried such online documents as Microsoft's MSDN and Binh Ly's COM
> tutorial. Both have stuff about automation object events but I couldn't
> figure it out.

> From the documentation for both technologies involved it should be simple
> but I've been playing around and just can't get it to work.

> Here is how I see I am supposed to implement an event for an automation
> object - say an event called OnMyEvent:

> On the VBA side it should be as simple as

> private sub application_onmyevent()
>      .....
> end sub

> then again it could be

> set application.onmyevent = GetRef(Name_Of_Subroutine_To_Handle_Event)

> Both are shown in various places in the VBA documentation. The code should
> mean that when the OnMyEvent event is fired from the automation object the
> associated code in the above script subroutine will be executed.

> On the Delphi side I'm lost. I've created an OLE Automation server via
> Delphi's wizard and told it to include event support code.

> This creates two interfaces one for methods etc and one for events. To add
> an event to my automation server I add a method in the event interface? Am
I
> correct? The Delphi documents seems to say this is what should be done
> anyway.....

> Now I assume that to fire the event I call FEvents.OnMyEvent? FEvents is
> part of the code generated by Delphi when event support is included and it
> does have an OnMyEvent method when I add the event via the Type Editor.
But
> FEvents always points to NIL.

> Is FEvents pointing to NIL because my VBA script isn't "sinking the event"
> or is it simply that I don't know what I am doing?

> Can someone please show me how to implement an automation object event in
> delphi, or at least point me in the right direction?

> Once I get the actual automation server part done I can go about figuring
> out what code I should be writting on the script side - I'm using the
divide
> and conquer theory here........

> Thanks,
> Christopher Fairbairn.

Re:VBA + Events Generated from Delphi based OLE Automation Object


Hi,

Quote
Binh Ly <b...@castle.net> wrote in message

news:875k25$32a3@bornews.borland.com...

Quote
> When you go into my EventSinkImp page, there is a DelphiSinkDemo.zip
> download that shows a very simple Delphi COM server that raises an event
the
> way you want it.

Thanks......

But the problem wasn't there after all.......... As I said I was trying out
two different things at the same time (always a mistake) and the problem
wasn't with the Automation server code it was with the code that was hosting
the Microsoft Scripting Control. There was one step I was doing one way and
I actually had to do it in the reverse order.

Once the two lines of code (load script / allow sinking of events) where
reversed everything started working... ie VBA could see the events the
server was firing.

The only other problem I have with this code is related to VBA so I'm
searching for that answer else where.

But thanks anyway,
Christopher Fairbairn.

Other Threads