Jump to content

FInd dynamically created form using Screen.Forms


artem_niko

Recommended Posts

Hello!

So, this is question: how fInd dynamically created form using Screen.Forms?

In short, the essence is this.
I create, dynamically, a form. But before I create it, I check whether it already exists, i.e. whether it was created earlier. If there was, then I close it and create it again.
The problem is that I can't find her by name. The name of the desired form is known to me in advance. I tried it through Screen.Forms[], but I can't find the right form:

function TMainForm.FindFormByName(const AName: string): TUniForm;
var
  i: Integer;
begin
  for i := 0 to Screen.FormCount - 1 do
  begin
    if (Screen.Forms[i].Name = AName) then
    begin
      Screen.Forms[i].Close;
    end;
  end;
end;

The Close event of the dynamic form contains the necessary and working code for destroying and unloading all its components. This code works correctly only if I close it with a cross, manually. I also need to close an existing form by name so that this Close event works automatically.

Link to comment
Share on other sites

10 minutes ago, Sherzod said:

 

This is not exactly my case and not exactly what I need. What follows the link may work if the form is created in advance, at the application development stage. In my case, the form is created dynamically. 
Therefore, I asked how it is possible (and is it possible) to find an already dynamically created form by name and close it -there may be many dynamically created forms, I need to find them specifically by name.

Link to comment
Share on other sites

1 hour ago, artem_niko said:

This is not exactly my case and not exactly what I need. What follows the link may work if the form is created in advance, at the application development stage. In my case, the form is created dynamically. 
Therefore, I asked how it is possible (and is it possible) to find an already dynamically created form by name and close it -there may be many dynamically created forms, I need to find them specifically by name.

Hello, You can use UniSession.FormsList.Count

if UniSession.FormsList.Count -1 > 0 then begin

for I := UniSession.FormsList.Count -1 do begin

     If TuniForm (UniSession.FormsList [I].Name = 'YOUNAme' then begin

          ......

      end;

end;
 

end;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...