Link to home
Start Free TrialLog in
Avatar of davelane
davelane

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davelane
davelane

ASKER

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