Link to home
Start Free TrialLog in
Avatar of msessions
msessions

asked on

modeless forms and popup windows

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.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

what means modeless?
Avatar of msessions
msessions

ASKER

sorry. poor choice of words. when i say modeless i mean non-modal.
can you show, how you create the "modeless" form
and how you call your popup-window?
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;
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.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.