Re: How do I use a TOleServer derived object properly? (Yet another interface question).
From: Kelly Leahy (kellyleahy_at_nospam.swbell.net)
Date: 01/14/04
- Next message: Guenther Wimpassinger: "Re: Service App Problem"
- Previous message: Ignacio Vazquez: "Re: public property in a TCustomEdit descendant"
- In reply to: ESPNSTI: "Re: How do I use a TOleServer derived object properly? (Yet another interface question)."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 13 Jan 2004 17:18:04 -0600
Comments inline.
> There seems to be some interface that supports some of the methods but
none
> of the properties (these properties happen to implement the events).
> When I try to do the above, I get an "Interface Not Supported" error,
which
> makes sense, since that interface (ISomeInterface) isn't used in the
> declaration of TTLB_OleServer;
events aren't properties. That's one problem. In order to handle events,
you need to go through a bunch of stuff with event sinks. I hate this
stuff, and I'm not sure I could really discuss it without just confusing you
further -- Sorry.
>
> > > And I take it I shouldn't do this:
> > >
> > > Procedure TForm1.FormCreate(Sender: TObject);
> > > Var
> > > oServer : TTLB_OleServer;
> > >
> > > Begin
> > > oServer := TTLB_OleServer.Create(Nil); //Or should I use Self here?
> > > Try
> > > oServer.Some_Procedure;
> > > Finally
> > > FreeAndNil(oServer);
> > > End;
> > > End;
> > >
> >
> > Probably not (though I'd have to look at what TOleServer.Destroy
actually
> > does to be sure.
>
> Seems to me that TOleServer.Destroy does some sort of reference counting,
> but I could be reading that wrong.
>
I think you're ok with using the object as an object reference, so long as
that's all you use it as. The problem really comes in when you try to use
it as both. However, I'm not really familiar with OLE servers myself, I've
always just dropped them on the form and never had any problems. Mostly, I
use non-UI com objects and for those I use a completely different style of
instantiation and treat them only as interfaces.
> > Since this object derives from TComponent (assuming you're correct) you
> > should be able to just drop it on the form from the designer. It should
> > have shown up on ActiveX tab or something else if you gave a different
> > location.
>
> I tried this and this seemed to make things a lot worse.
> And this is where the confusion comes into play again, if you're dropping
it
> on a form, aren't you using it as an object reference again, which from
what
> I gather, you're not supposed to do?
>
> The following is what I'm doing now, which works reasonably well, but I'm
> still getting an access violation every once in a while:
>
> Procedure TForm1.FormCreate(Sender: TObject);
> Var
> oServer : TTLB_OleServer;
>
> Begin
> oServer := TTLB_OleServer.Create(Nil); //Or should I use Self here?
> oServer.Some_Procedure;
> oServer := Nil;
> End;
>
that looks fine, so long as that's the only place you are using the server.
If you need access to it in other places, then this isn't a good idea at
all.
>
> I get the feeling that I'm not doing things right (and that's why I'm
> getting AVs).
> What I'm thinking is that there has to be some "right way / standard way"
to
> deal with these TOleServer classes since this is defined by Delphi and the
> TLB pas file is generated by Delphi.
>
By the way, when you imported the TLB, did you tell it to support events? I
think this is a checkbox somewhere in the import dialog, iirc.
>
> FYI, below is the top of the declaration of the actual class in the TLB
pas
> file that I'm using (not sure if this clarifies anything).
> // *********************************************************************//
> // OLE Server Proxy class declaration
> // Server Object : TConnection
> // Help String : Connection Class
> // Default Interface: IConnection
> // Def. Intf. DISP? : No
> // Event Interface: _IConnectionEvents
> // TypeFlags : (2) CanCreate
> // *********************************************************************//
> TConnection = class(TOleServer)
>
> What is interesting is that TConnection defines some event properties that
> look like they're intended to implement the _IConnectionEvents interface
> events.
> When I use these properties, the events simply don't work, however if I
> implement a IConnectionEvents class and set the EventDispatch properties
of
> TConnection to that class then the events work ok.
>
That's right. That's how the event sinks (that I mentioned hating) work.
Kelly
- Next message: Guenther Wimpassinger: "Re: Service App Problem"
- Previous message: Ignacio Vazquez: "Re: public property in a TCustomEdit descendant"
- In reply to: ESPNSTI: "Re: How do I use a TOleServer derived object properly? (Yet another interface question)."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|