BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Retrofitting a COM Interface to an MDI TForm?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Andrew Fiddian-Green
Guest





PostPosted: Thu Dec 16, 2004 6:48 pm    Post subject: Retrofitting a COM Interface to an MDI TForm? Reply with quote



Hi.

I have an existing D7 application that uses multiple MDI child forms, and I
would like to retrofit a COM automation interface to it.

Specifically, I would like to do something similar to what MS does with
"Excel.Application.ActiveSheet.DoSomething". My approach is to add an
ImyApplication interface to my main form, and an ImyActiveSheet interface to
my MDI child form...

I could imagine that an MDI child window might be accessed by the
ImyActiveSheet interface and at the same time the user might try to close
the child via the normal application user interface commands; so I suppose
that I need to do something in the OnCloseQuery event and/or override the
_AddRef and _Release methods so as to prevent the user closing a form that
is currently refcounted by COM?

Question: does anyone have any suggestions / examples about how to do this?

Regards,
AndrewFG


Back to top
Michael Moreno
Guest





PostPosted: Sat Dec 18, 2004 6:25 am    Post subject: Re: Retrofitting a COM Interface to an MDI TForm? Reply with quote



Quote:
I have an existing D7 application that uses multiple MDI child forms, and I
would like to retrofit a COM automation interface to it.

Specifically, I would like to do something similar to what MS does with
"Excel.Application.ActiveSheet.DoSomething". My approach is to add an
ImyApplication interface to my main form, and an ImyActiveSheet interface to
my MDI child form...

I could imagine that an MDI child window might be accessed by the
ImyActiveSheet interface and at the same time the user might try to close the
child via the normal application user interface commands; so I suppose that I
need to do something in the OnCloseQuery event and/or override the _AddRef
and _Release methods so as to prevent the user closing a form that is
currently refcounted by COM?

Question: does anyone have any suggestions / examples about how to do this?

I have done something relatively similar recently : a plug-in of
ActiveFormX. You will see below why it is similar and what I did :

1 - Create a standard IMyPlug interface with the methods
- IsCanClose
- Close
- ...

2 - Create all the ActiveFormX and add to them the IMyPlug interface

3 - Create a standard MDI child form that can manage any ActiveFormX
that implements the IMyPlug interface

How does it work ?

It is very simple : when the user tries to close the MDI Form I first
call the IMyPlug.IsCanClose method of the ActiveFormX to be sure there
is no treatment running. In other words that the user can close it. If
answer is IMyPlug.IsCanClose = true then I close the form and
everything will be freed as expected since I manage the ActiveFormX at
the form level.

The ActiveFormX can ask the form to be closed too by calling the
IMyPlug.Close method.

So in your case you simply need to fire an event to the user to tell
him that the ActiveForm is closing (which is what I do by calling the
IMyPlug.Close method). But you may also need to ask the one that
control the form if actually you can close (which is what I do by
calling the IMyPlug.IsCanClose method).

Michael

--
Drakkhen

http://michael.moreno.free.fr/


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.