Making a visible form modal

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?
davelaneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andrewjbCommented:
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
davelaneAuthor Commented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

andrewjbCommented:
Things like timer events will still occur in either form.
0
davelaneAuthor Commented:
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
andrewjbCommented:
Nope - Modal forms in general. Was just reminding you :-)

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.