Solved

Making a visible form modal

Posted on 2003-11-26
6
253 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

705 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

20 Experts available now in Live!

Get 1:1 Help Now