artem_niko Posted November 30, 2022 Share Posted November 30, 2022 Hello! I need, in a loop, to go through all the child, dynamically created unitabsheets in the parent UniPageControl, find the desired UniTabSheet by its name and call the OnBeforeActive event from it. How can this be done, how to pass parameters to a procedure where ... ? procedure TMainForm.UniPageControl1ChangeValue(Sender: TObject); var i: integer; begin for i := UniPageControl1.ControlCount - 1 downto 0 do if UniPageControl1.Controls[i] is TUniTabSheet then begin TUniTabSheet(UniPageControl1.Controls[i]).OnBeforeActivate(...); end; end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 15 minutes ago, artem_niko said: I need, in a loop, to go through all the child, dynamically created unitabsheets in the parent UniPageControl, find the desired UniTabSheet by its name and call the OnBeforeActive event from it. Sorry, for what purpose !? Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 30, 2022 Author Share Posted November 30, 2022 6 minutes ago, Sherzod said: Sorry, for what purpose !? Because I'm looking for a solution to a problem that is slowing down my development right now. In one of the topics, I said that I have the following sequence: the parent of the Uni PageControl for dynamically created unitabsheets, which in turn are the parents for dynamically created uniframes (each UniFrame on its UniTabSheet). So, I need, when changing tabs (when moving through them in the parent Uipagecontrol) to find the desired tab by name and trigger the UniTabSheet event from it.OnBeforeActive, which passes a variable from the UniFrame to the main program. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 i.e. Do you want to activate the tab eventually? Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 30, 2022 Author Share Posted November 30, 2022 1 minute ago, Sherzod said: i.e. Do you want to activate the tab eventually? Yes, something like that... Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 38 minutes ago, artem_niko said: Yes, something like that... You can try something like this I guess: ... if (UniPageControl1.Controls[I] is TUniTabSheet) then begin UniPageControl1.ActivePage := (UniPageControl1.Controls[I] as TUniTabSheet) end; ... Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 30, 2022 Author Share Posted November 30, 2022 4 minutes ago, Sherzod said: You can try something like this I guess: ... if (UniPageControl1.Controls[I] is TUniTabSheet) then begin UniPageControl1.ActivePage := (UniPageControl1.Controls[I] as TUniTabSheet) end; ... Will this trigger the OnBeforeActivate event on a dynamically created UniTabSheet? Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 30, 2022 Author Share Posted November 30, 2022 This code does not trigger the OnBeforeActivate event. Instead, when you open the first tab, and then the second one and start clicking on them, then clicking on the second tab immediately throws it to the first tab and makes it active, while the code in OnBeforeActivate does not work: procedure TMainForm.UniPageControl1Change( Sender: TObject); var i: integer; begin for Счетчик := UniPageControl1.ControlCount - 1 downto 0 do if UniPageControl1.Controls[i] is TUniTabSheet then begin UniPageControl1.ActivePage:=(UniPageControl1.Controls[i] as TUniTabSheet); end; end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 var Allow: Boolean; ... if Assigned(TUniTabSheet(UniPageControl1.Controls[I]).OnBeforeActivate) then TUniTabSheet(UniPageControl1.Controls[I]).OnBeforeActivate((UniPageControl1.Controls[I] as TUniTabSheet), Allow) Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 30, 2022 Author Share Posted November 30, 2022 This is global var in MainForm? var Allow: Boolean; I'm writing that: procedure TMainForm.UniPageControl1ChangeValue(Sender: TObject); var i: integer; begin for i := UniPageControl1.ControlCount - 1 downto 0 do if UniPageControl1.Controls[i] is TUniTabSheet then begin if Assigned(TUniTabSheet(UniPageControl1.Controls[i]).OnBeforeActivate) then TUniTabSheet(UniPageControl1.Controls[i]).OnBeforeActivate((UniPageControl1.Controls[i] as TUniTabSheet), Allow) end; end; I'm not getting errors, but, my simple code in UniTabSheet.OnBeforeActivate not work: procedure TUniFrame1.UniTabSheet1BeforeActivate(Sender: TObject; var AllowActivate: Boolean); begin ShowToast((Sender as TUniTabSheet).Name); end; Message not showing... Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 7 minutes ago, artem_niko said: This is global var in MainForm? Doesn't matter. 7 minutes ago, artem_niko said: I'm not getting errors, but, my simple code in UniTabSheet.OnBeforeActivate not work: Are you sure that the event has been assigned? Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 30, 2022 Author Share Posted November 30, 2022 2 minutes ago, Sherzod said: Are you sure that the event has been assigned? You mean make this when my UniTabSheet is creating? If "yes", so my UniTabSheet exist in my BPL file... Look at the scheme: On this scheme, UniTabSheetBPL - this is the tab where the code I need is located in the OnBeforeActivate event. You see, if there is a way, knowing the name of the global, inside the whole UniFrame1, variable that is stored in UniFrame1, to somehow pull it into MainForm, then UniTabSheetBPL would not exist at all. I have to use it somehow, because it has an OnBeforeActivate event, through which I wanted to get this variable. Without this tab, the scheme would be simpler: Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 I mean, is the event assigned at all? Can you check again? Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 30, 2022 Author Share Posted November 30, 2022 6 minutes ago, Sherzod said: I mean, is the event assigned at all? Can you check again? No, I didn't dynamically assign this event... Then the question is, will this work if I: 1. Create the OnBeforeActivate event and assign it to a dynamically created Tabsheet; 2. From the UniPageControl1 menu to (Parent as TUniTabSheet), because UniTabSheet is the parent for Uni Frame 1, the contents of which are all on UniTabSheetBPL, in the same BPL file. Something, like that: procedure TMainForm.UniTabSheet(Sender: TObject; var AllowActivate: Boolean); var i: integer; begin for i := (Parent as TUniTabSheet).ControlCount - 1 downto 0 do if (Parent as TUniTabSheet).Controls[i] is TUniTabSheet then begin if Assigned(TUniTabSheet((Parent as TUniTabSheet).Controls[i]).OnBeforeActivate) then TUniTabSheet((Parent as TUniTabSheet).Controls[i]).OnBeforeActivate(((Parent as TUniTabSheet).Controls[i] as TUniTabSheet), Allow) end; end; Will it work? P.S. When I applying this get, I'm get error, when try change pages in UniPageControl: Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 12 minutes ago, artem_niko said: 1. Create the OnBeforeActivate event and assign it to a dynamically created Tabsheet; Yes. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 13 minutes ago, artem_niko said: 2. From the UniPageControl1 menu to (Parent as TUniTabSheet), because UniTabSheet is the parent for Uni Frame 1, the contents of which are all on UniTabSheetBPL, in the same BPL file. Sorry, seems I don't understand your case. But I also know that you can't create a simple test case to see the problem. Quote Link to comment Share on other sites More sharing options...
artem_niko Posted November 30, 2022 Author Share Posted November 30, 2022 Quote 2. From the UniPageControl1 menu to (Parent as TUniTabSheet), because UniTabSheet is the parent for Uni Frame 1, the contents of which are all on UniTabSheetBPL, in the same BPL file What about this? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 30, 2022 Share Posted November 30, 2022 I replied above. 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.