Solved

modeless forms and popup windows

Posted on 2002-06-17
7
923 Views
Last Modified: 2010-04-04
i have a modeless form that is created from my main form. i've noticed something that i don't unserstand and i thought you guys might be able to help me out. after i create my modeless form from my mainform and then generate a messagedlg popup or some other popup window from my modeless form, my modeless form is sent to back behind any other windows open on my desktop..usually mainform. if i minimize all windows except my modeless form and generate a popup window, everything looks fine. is there a z-order issue here with my app's forms? i need for the modeless form to be just behind the popup windows and not be "sent to back" behind all other windows. basically i want the same "look and feel" that i would expect from a modal form except that i have modeless. thanks to all who respond.
0
Comment
Question by:msessions
  • 4
  • 2
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7083894
what means modeless?
0
 

Author Comment

by:msessions
ID: 7083905
sorry. poor choice of words. when i say modeless i mean non-modal.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7083914
can you show, how you create the "modeless" form
and how you call your popup-window?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:msessions
ID: 7083944
from my mainform i create my non-modal form with this code. "Id" is just the form Id that i assign to tag to keep track of what forms are open and what forms need to be created:

procedure TfrmMain.ShowOrCreateForm(Id: integer);
var
frmindex: Integer;
Found: Boolean;
aForm: TfrmTicket;
begin
{Initialize the Variables}
 Found := False;
 aForm := nil;

{Loop over all forms of the application }
 for frmindex := 0 to Pred(screen.FormCount) do
   begin
     { Check if the form already exists by looking at its tag which was assigned an ID on creation}
     if Screen.Forms[frmindex] is TfrmTicket then
       if Screen.Forms[frmindex].Tag = Id then
         begin
           { If so, assign it }
           aForm := TfrmTicket(Screen.Forms[frmindex]);
           Found := True;
         end;
   end;

 {If a form of our formclass was not found, create it}
 if (Not Found) then
   begin
     try
        aForm := TfrmTicket.Create(self);
     except
       MessageDlg('Cannot create form for this user action. Please contact TTS support.', mtError,[mbOK],0);
       exit;
     end;
   end;
{If a form of our formclass was found, show it}
 if (Assigned(aForm)) then
   with aForm do
     begin
       //assign Ticket ID to form tag
       Tag := dmTTS.TicketID;
       Show;
       if WindowState = wsMinimized then
         WindowState := wsNormal;
       BringToFront;
     end;
end;

form save from my non-modal form. the messagedlg 'Save changes?' causes the "problem" that i'm seeing:

function TfrmTicket.DoFormClose:boolean;
begin
  result := false;
  if (spTicket.state in [dsInsert,dsEdit]) then
     if MessageDlg('Save Changes?',mtConfirmation,[mbYes,mbNo],0) = mrYes then
        begin
          if DoSave then
             begin
               OK2Close := True;
               result := true;
             end
          else
             begin
             end;
        end
     else
        begin
          spTicket.CancelUpdates;
          if RecInserted and (dmTTS.TicketID > 0) then
             begin
               dmTTS.spDeleteTicket.Parameters.ParamByName('@ID').Value := dmTTS.TicketID;
               dmTTS.spDeleteTicket.ExecProc;
             end;
          OK2Close := True;
          result := true;
          exit;
        end
  else
    begin
      OK2Close := True;
      result := true;
    end;
end;
0
 

Author Comment

by:msessions
ID: 7083959
i think that if you build a simple sample delphi app and create a non-modal form from your mainform and then pop down a button on your non-modal form that calls a messagedlg then you'll see what i'm talking about. make sure you don't minimize mainform. open up a couple of other apps like Word, outlook, etc. before you do this. this should give you some idea what i'm seeing. thanks.
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 200 total points
ID: 7084501
you might try a standard win system Message box


if MessageBox(frmTicket.Handle,'Save Changes?', 'Save Changes', MB_YESNO or MB_ICONQUESTION) = IDYES then




the frmTicket.Handle indicates where the focus will be returned to after the message box closes
0
 

Author Comment

by:msessions
ID: 7084842
that seemed to work. what about other controls that take focus away from this non-modal form. is their a more general solution? for example, i have a grid that has a lookup column that when the user click to drop down the list item it display another grid(devexpress quantum grid). when the lookup column list item grid is displayed i'm seeing the same thing with the message dialog pop-up windows. thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

15 Experts available now in Live!

Get 1:1 Help Now