Solved

Making a visible form modal

Posted on 2003-11-26
6
256 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
  • 3
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 125 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 125 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now