Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

modeless forms and popup windows

Posted on 2002-06-17
7
Medium Priority
?
946 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 800 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

916 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