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


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



Relevant Pages

  • Re: Interop Interface from .Net to VB6
    ... The tlb I get is not generated by the .net Compiler, but by my build process step of calling regasm ... implement the interface ICommand. ... Again since, in my original system, the interface is created in .Net and then the tlb is generated from it, perhaps this is a side effect of doing things in a different order or a different dependancy chain. ... I was kinda expecting that my .Net dll would still be the same but that the tlb would effectively include better info that would have been generated with my other method. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: object as parameter
    ... Interfaces Type Library Version 1.0" in the list of references. ... interface IDatabaseData: IDispatch ... I have a question on composing tlb at this point ... its similar to the issue with a dll and compatibility settings when you add ...
    (microsoft.public.vb.general.discussion)
  • Re: idl questions
    ... changed version number but left interface name the same ... un-referenced existing tlb ... Private moCProjectSpec as cProjectSpecConcrete ... I've been using a tlb created from idl and want to add some stuff to it. ...
    (microsoft.public.vb.general.discussion)
  • Re: How to Repubilsh the user defined datatypes in Atl component ?
    ... > Thank you for your answer, but I have only *.tlb and binarie files. ... You can get by with importlib alone: ... You seem to misunderstand how type libraries work. ... things happen if the same interface is defined in more than one TLB. ...
    (microsoft.public.vc.atl)
  • Re: Return collection interfaces or collection objects???
    ... I like returning an interface better than ... Create sone specific collection instance, ... dependancy - the caller will be returned an object reference and will ...
    (microsoft.public.dotnet.languages.csharp)