artem_niko Posted November 22, 2022 Share Posted November 22, 2022 Good afternoon! In general, such a task. On Pagecontrol , I dynamically create UniTabSheet1 . On the created UniTabSheet1, my UniFrame1 is dynamically loaded. The essence of the task: according to a certain condition, using UniTimer1, delete both UniFrame1 and UniTabSheet1, and not just delete, but with the destruction of components so that there are no AV errors later. Currently, so far, I'm going this way: In the OnClick event in UniButton, it is written like this: procedure TUniFrame1.Uni Button1Click(Sender: TObject); begin Free; end; I call the code above via UniTimer1: procedure TUniFrame1.UniTimer1Timer(Sender: TObject); begin if N = 0 then begin UniButton1.OnClick(Sender); end; end; As a result, my UniFrame1 disappears, I understand that it is deleted, but UniTabSheet1 remains. Actually, the question is, how to also completely destroy UniTabSheet1? Or how to register the destruction code in the button event at once UniFrame1? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 22, 2022 Share Posted November 22, 2022 15 minutes ago, artem_niko said: In general, such a task. On Pagecontrol , I dynamically create UniTabSheet1 . On the created UniTabSheet1, my UniFrame1 is dynamically loaded. The essence of the task: according to a certain condition, using UniTimer1, delete both UniFrame1 and UniTabSheet1, and not just delete, but with the destruction of components so that there are no AV errors later. Hello, Just use the Close method, for example: procedure TMainForm.UniButton1Click(Sender: TObject); begin UniPageControl1.ActivePage.Close; end; Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 22, 2022 Author Share Posted November 22, 2022 4 minutes ago, Sherzod said: Hello, Just use the Close method, for example: procedure TMainForm.UniButton1Click(Sender: TObject); begin UniPageControl1.ActivePage.Close; end; This won't work because UniPageControl isn't on my frame. It is the parent for UniTabSheet, which is the parent for UniFrame1 proper. Maybe there is some way to determine the parent of the component and delete it? Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 22, 2022 Author Share Posted November 22, 2022 1 hour ago, artem_niko said: This won't work because UniPageControl isn't on my frame. It is the parent for UniTabSheet, which is the parent for UniFrame1 proper. Maybe there is some way to determine the parent of the component and delete it? That's it, I figured it out myself already and made a decision. That's how it's done: procedure TUniFrame1.UniButton1Click(Sender: TObject); begin (Parent as TUniTabSheet).Free; end; Also, I get this message: Could not set cell position: row: [0], column:[1] :Cannot read properties of null (reading 'isModel') What can this message be related to? As such, there is no error, but maybe because of it, the closing code in the timer does not work the second time when I create the tab and frame dynamically again. Quote Link to comment Share on other sites More sharing options...
bahry Posted November 22, 2022 Share Posted November 22, 2022 if the Parent of the pagecontrol is the mainform you can call mainform.PageControl1.ActivePage.Close; Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 22, 2022 Author Share Posted November 22, 2022 15 minutes ago, bahry said: если родительским элементом pagecontrol является основная форма вы можете вызвать mainform.PageControl1.ActivePage.Закрыть; Well, in general, yes, that's right. On the MainForm of the main application, I have UniPageControl1, on which UniTabSheet1 is created dynamically and immediately UniFrame1 is loaded dynamically to this tab. Therefore, I need, by clicking on the button on the loaded UniFrame1, to close its parent (UniTabSheet1), which has its parent (UniPageControl1). Will it work? mainform.PageControl1.ActivePage.Close; After all, my UniFrame1 knows nothing about UniPageControl1, which is located on MainForm... Here, I drew a diagram to make it clearer who is the parent of whom: My code is in the button above - it works, everything closes as it should, but when I reconnect UniFrame1, the updated UniFrame1 does not load, because of this error, most likely: Or because xxx.dll is not unloaded somehow. Everything works only after restarting the server, which is not correct. 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.