artem_niko Posted November 10, 2022 Share Posted November 10, 2022 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. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 10, 2022 Share Posted November 10, 2022 22 minutes ago, artem_niko said: I check whether it already exists, i.e. whether it was created earlier. Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 10, 2022 Author Share Posted November 10, 2022 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. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted November 10, 2022 Share Posted November 10, 2022 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; Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 11, 2022 Author Share Posted November 11, 2022 Quote for I := UniSession.FormsList.Count -1 do begin Is it correctly? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted November 11, 2022 Share Posted November 11, 2022 25 minutes ago, artem_niko said: Is it correctly? Sorry, for I := UniSession.FormsList.Count -1 downto 0 do begin //begin from TOP form 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.