Jump to content

Programmatically calling the UniTabSheet event.OnBeforeActive from the parent UniPageControl


artem_niko

Recommended Posts

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;

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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:

image.png.c2c2414db6bc0b0e11c3a8e08cca9ba0.png

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:

image.png.d9408b2795f899779a82b6fd7b334d21.png

Link to comment
Share on other sites

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:

image.png.81cde1029dfedaf6337000ef66ab12fc.png

Link to comment
Share on other sites

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.

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...