?
Solved

Making a visible form modal

Posted on 2003-11-26
6
Medium Priority
?
265 Views
Last Modified: 2010-04-05
Here is the scenario,
I have an application that has 2 main forms DATA and MAP. Both forms will always be open and visible. OK, in DATA when you click a button to input a new entity a modal form DATACHILD appears to facilitates input. An option is to select an element from MAP: I want to then use the MAP form that is already visible (because of MAP loading time I cannot fire it up anew every time). How do I get the MAP form to now act as a modal form for the DATACHILD form. Is this possible?
0
Comment
Question by:davelane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 500 total points
ID: 9825240
Hi,

What about enabling both MAP and DATACHILD forms simultaneously (i.e. MAP will not be modal over the child form but will be enabled).

Let MAP form is decalred in unit2. Then on your DATACHILD form (Form3 in the example below) you have a button that enables the MAP form this way:

uses unit2; // MAP form is declared there

procedure TForm3.Button1Click(Sender: TObject);
begin
  EnableWindow(MAP.Handle, True);
  MAP.SetFocus;
end;

Note: MAP is the name of the MAP form.

Regards, Geo
0
 
LVL 12

Assisted Solution

by:andrewjb
andrewjb earned 500 total points
ID: 9825246
You could

MAP.Hide()
Map.ShowModel()
Map.Show()

?


or duplicate the functionality of the ShowModal function, which acts a a special filtering message loop, though that's nasty.

Will the first suggestion not do it?
0
 

Author Comment

by:davelane
ID: 9825911
Did a bit of both: This function can be called from any form and makes the MAP form behave like a ModalForm. Any caveats to the following method?

function MAP.SelectFromMap: TModalResult;
var
  PrevActiveWindow: HWnd;
begin
  try
    Self.ButtonOK.Visible := true;
    Self.ButtonCancel.Visible := true;
    Self.Return := mrNone;

    // Enable myself and disable the form that called me
    PrevActiveWindow := GetActiveWindow;
    EnableWindow(Self.Handle, true);
    EnableWindow(PrevActiveWindow, false);
    SendMessage(Self.Handle, CM_ACTIVATE, 0, 0);
    SetActiveWindow(Self.Handle);
    repeat
      Application.HandleMessage;
    until Self.Return <> mrNone;
    Result := Self.Return;

    // Disable myself and reenable that called me
    SendMessage(Self.Handle, CM_DEACTIVATE, 0, 0);
    EnableWindow(Self.Handle, false);
    EnableWindow(PrevActiveWindow, true);
    SetActiveWindow(PrevActiveWindow);
  finally
    Self.OK.Visible := false;
    Self.Cancel.Visible := false;
  end;
end;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:andrewjb
ID: 9825950
Things like timer events will still occur in either form.
0
 

Author Comment

by:davelane
ID: 9826037
Yeah? But is that not also the case with ModalForms in general? If not then what have I done in the function above to cause this (presuming it is a bad thing).
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9826063
Nope - Modal forms in general. Was just reminding you :-)

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question