How to get a list from all opened forms of my software?

自闭症网瘾萝莉.ら 提交于 2019-12-22 05:40:06

问题


I want to ask the user to close all opened forms before terminate my application.

How can I automatically get a list from opened forms?

I'm using Delphi 2006, and don't using form's Auto-Create, but I'm using the auto created form's referenced var with Application.CreateForm.

My regards.


回答1:


Have a look at Screen.FormCount and Screen.Forms.




回答2:


A possible solution (I use in C#) is to store every opened form instance in a list var. For example you could have a global list named openedForms; when every form is created, form itself can add its reference to openedForms and remove it when closing.
When user tries to close your app, you could check that list count is greater than zero and, if user wants really close, you close gracefully every form instance contained in openedForms before shutting the app down.




回答3:


I use

Main.MDIChildCount >0

for Child froms




回答4:


var
i:integer;
begin
  with Application do
   for i:=0 to componentcount-1 do
    if components[i] is TMyCustomForm          //your form class here, or simply TForm
    then showmessage(components[i].Name);
end;

Shows MDI and non-MDI forms.



来源:https://stackoverflow.com/questions/7529810/how-to-get-a-list-from-all-opened-forms-of-my-software

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