Solved

modeless forms and popup windows

Posted on 2002-06-17
7
931 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 34

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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