[fpc-pascal] support for using an activex
Ludo Brands
ludo.brands at free.fr
Wed May 25 17:28:50 CEST 2011
The code in article
http://www.informit.com/articles/article.aspx?p=130494&seqNum=5 goes a long
way in doing what you want to do. Unit Eventsink does pretty much of the
legwork. You should remove the procedure register since that is the Delphi
way to get a component on the toolbar. Remove also the {$IFDEF VER100} and
{$ENDIF}. The unit actually includes the code for InterfaceConnect!!
In the MainForm unit you'll have to do in a TForm1.Create
EventSink1:=TEventSink.Create(Self);
EventSink1.OnInvoke:=@EventSink1Invoke;
because the example assumes you have dropped the component on the form and
entered EventSink1Invoke in the properties box.
As for the tlb conversion, in your case
IEventIntfEvents = dispinterface
['{168F5642-5751-49F5-9AA4-B8A7A5F6A5B8}']
end;
should do (that is for the events part). AFAIK the procedure and dispid
definitions are only needed for the server. You are only concerned with
dispid's. No need to create prototypes for OnCommChanged() etc.
EventSink1Invoke would be a simple
case DispID of
1: // do CommChanged
2: // do StatesChanged
...
end;
Ludo
-----Message d'origine-----
De : fpc-pascal-bounces at lists.freepascal.org
[mailto:fpc-pascal-bounces at lists.freepascal.org] De la part de Roberto
Padovani Envoyé : mercredi 25 mai 2011 16:01 À : FPC-Pascal users
discussions Objet : Re: RE : RE : RE : RE : [fpc-pascal] support for using
an activex
2011/5/25 Ludo Brands <ludo.brands at free.fr>:
> Regarding the tlb to pascal "conversion", AFAIK there is no support in
> fpc. Delphi is clearly better equiped to work with COM objects.
>
> I have also been playing around with a generic eventsink class but the
> problem is that events can have parameters (and a lot do). Your
> suggestion of using TNotifyEvents could work for events without
> parameters. You could leave the parameter stuff to the user of the
> eventsink, eventually helping him by exposing the number and type of
> parameters, but that means that the user has to have a reasonable good
> understanding of COM, including the data types compatible with COM
> marshalling.
>
Thanks for the explanation. In fact, that is the reason why I called it
TSimpleEventSink, meaning that it was good for simple situation. In my case,
for example, the activex controls a hardware stuff which only request the
user to take an action sometimes. In the C++ source code for the class
Device I have:
[
uuid(168F5642-5751-49F5-9AA4-B8A7A5F6A5B8),
helpstring("_IDeviceEvents Interface")
]
dispinterface _IDeviceEvents
{
properties:
methods:
[id(1), helpstring("method OnCommChanged")] HRESULT OnCommChanged();
[id(2), helpstring("method OnStatesChanged")] HRESULT
OnStatesChanged();
[id(3), helpstring("method OnContact")] HRESULT OnContact();
[id(4), helpstring("method OnMeasUpdate")] HRESULT OnMeasUpdate();
};
where this four simple events only alert the user about a change situation;
then the user takes the suitable actions. Do you think it could work for me?
Now I'm trying to write by hand a minimalist tlb, looking for the
definitions in the activex source code....
Thanks a lot!!
Roberto
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list