How can I show a Delphi non-modal form in my Outlook AddIn?
How can I show a Delphi non-modal form in my Outlook AddIn?
|
Victor Ulloa
Guest
|
Hi,
I need to show a non-modal Delphi form in a Outlook add-in. My code looks like this:
procedure TAddInModule.adxQueriesControls0Click(Sender: TObject);
var
f : TfrmMyform;
begin
f := TfrmMyform.CreateEx(self);
try
f.ShowModal;
finally
f.free;
end;
end;
Everything's OK, but if we replace the "ShowModal" for simply "Show", the form opens and inmediatly closes.
What am I missing?
Thanks! |
|
Posted 11 Aug, 2006 09:43:49
|
|
Top
|
|
Nicholas Glasier
Guest
|
If you just have f.Show then the code afterwards will run right away and the form will be freed with f.Free. Try going into a loop that stops the form being freed until you are finished with it. Something like:
while f.visible do
application.ProcessMessages;
f.Free;
Nick
|
|
Posted 11 Aug, 2006 18:38:02
|
|
Top
|
|
Victor Ulloa
Guest
|
Oh my God! I'm embarrased! :oops:
That's so simple...
I promise not to write to the forums 'til the morning after. Sometimes at 2:00a.m. your brain is somehow disconected from the keyboard!
Thanks. |
|
Posted 12 Aug, 2006 09:27:37
|
|
Top
|
|
Victor Ulloa
Guest
|
Hey, hey, hey!
It's no so simple...
The Outlook add-in is NOT an application, so I can't access the global Application variable...
So again... how can I show a non-modal Delphi form in a Outlook add-in
|
|
Posted 12 Aug, 2006 16:19:07
|
|
Top
|
|
Nicholas Glasier
Guest
|
Hi Victor, try this,
1. Add Forms to the AddinModule units uses clause. The application object is defined in that file.
2. Get a handle to the host app in your addin initialize event handler:
procedure TAddInModule.adxCOMAddInModuleAddInInitialize(Sender: TObject);
begin
Application.Handle := GetActiveWindow;
end;
Free it in your finalize event:
procedure TAddInModule.adxCOMAddInModuleAddInFinalize(Sender: TObject);
begin
Application.Handle := 0;
end;
Good luck Nick
|
|
Posted 12 Aug, 2006 16:53:39
|
|
Top
|
|
Nicholas Glasier
Guest
|
Something else you may need to consider Victor,
When you display a form non-modally, it is possible to click on the host app window and hide your add-in window behind it. However, your addin is considered a part of the host app by the system, so it's windows don't have an icon on the taskbar. This can make it difficult to get your addin window back on top again.
If you don't want your users to have to resize the hostapp window so they can see the addin window you are either going to have to make it StayOnTop
or maybe use a notification icon component so there is something in the icon tray they can use to get the addin window back on top easily.
Regards Nick |
|
Posted 12 Aug, 2006 17:10:38
|
|
Top
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2887
Joined: 2004-04-05
|
Hi Nick and Victor,
Nick, thank you for the help.
Victor, do you have any problems with non-modal forms?
|
|
Posted 14 Aug, 2006 05:10:42
|
|
Top
|
|