Problems in Showmodal after assigning to Setparent(..)

醉酒当歌 提交于 2019-12-01 00:00:57

Don't be surprised, what you are trying is unusual at best. ShowModal achieves the modal effect by disabling all the windows of the calling thread but the modal form. Since your parent form do not belong to the same thread, not even to the same process, it does not get disabled. See DisableTaskWindows in forms.pas to understand how the forms are disabled when 'ShowModal' is called.

You have to devise your own modal procedure; test if the application is parented in a top level window that's not the desktop, disable that window if that's the case.

But if I were you I would think on the design first, what if, f.i., you close the parent form, how do you end the parented form's process?


edit: for 3rd comment below - you might try having the modal form "owned" by the MainApps's form. Similiar to forms being owned by the application main form while MainFormOnTaskbar is true. See owned windows on Window Features topic of msdn.
var
  frmDialog: TfrmDialog;
begin
  [...]
  frmDialog := TfrmDialog.Create(Self, dtLogout);
  try
    SetWindowLong(frmDialog.Handle, GWL_HWNDPARENT, GetAncestor(Handle, GA_ROOT));
    iMsgResult := frmDialog.ShowModal;
    [...]


I'd humbly suggest you to ask a question on a suggestion of a design for what you want to achieve, for instance, if it is about code reuse you could host your SubApps forms in a dll... This design is fragile, you may continue to run into problems with it...

Try making your windows "system modal" instead of "application modal". Actually, I have no idea if you can even do that. It might be impossible, or a bad idea. In fact, the whole question gives me the "bad idea" smell.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!