Jump to content

TUniTabSheet OnBeforeActivate & OnBeforeFirstActivate Events


Tim Mckay

Recommended Posts

Howdy gurus of Uni,....

I have an issue I am trying to resolve with TUniTabSheets, pertaining to the OnBeforeActivate & OnBeforeFirstActivate events.

When the app starts, and say TabSheet1 is the first tab, with those events defined, they do not fire.   As a user, I would need to click on a different tab, and then back to this TabSheet1 again, and then both of those events would fire as expected.

To reproduce this, you can use the "PageControl - BeforeActivate" (pageact.dproj) demo app, and make these changes (this describes the OnBeforeFirstActivate, but the exact same is occuring with the OnBeforeActivate event as well):

  1. Create a new OnBeforeFirstActivate event handler with this one line of code: ShowToast('entered event');

 

Now, run the project. 

a) When the application starts, TabSheet1 is active, but that event does NOT fire.  If I click any other tab, then click this first one again, it does fire.   

b) If I run the application a second time, as a fresh session, if I click the TabSheet1 tab FIRST, also the event does not fire.  I must in that case click another tab, and come back to this tab.

 

My ultimate goal is as follows:

I have built a web portal based on the mdemo (main UniDemo).  When I click on the NavTree items on the left, the tabs open and close as expected.  What I want to achieve is to capture the state of all the TDataSources (probably with a bookmark) prior to the user opening a new tab or when leaving the tab; and, reciprocally I want to restore those save points when the user comes BACK to the tab.

In my project, just like the mdemo, I have the NavTree built, and in the NavMenuClick event handler, I am creating the TabSheets at run time, and am hoping to assign those events to "generic" handlers on my main form.  (such as "Generic_OnBeforeFirstActivate", "Generic_OnBeforeActivate" and "Generic_OnClose").   In that NavMenuClick I follow the exact same pattern as the mdemo application, but am trying to assign these Generic_* event handlers to the TUniTabSheet when it is created.  I thought I could 'work around' the issue by calling the event handlers manually -- which works because they do fire.... but there are two negative side-effects:

1)   The tabs stop closing and re-opening correctly, almost like there's a memory corruption.  That's not important for now, I can probably work around that some other way.

2)  The issue then is that if I manually force those events to fire in code, when the user goes from tab to tab they will fire those events AGAIN.  (Firing the event in code doesn't seem to trigger whatever flag that the control knows about the First Activation has occurred).

 

So my question is :

a)  What is a better approach to capturing the events of a user going from tab to tab on a TUniPageControl?

b)  Is there some way to have the OnBeforeFirstActivate and OnBeforeActivate events to fire when a tab is created and made active in code at run-time?  (because the PageAct demo project is also setting the ActiveTab in code the same way I am, it would seem consistent that setting this in code does not fire this event at all).

 

Using UniGui 1.90.0.1518 on Delphi XE7.

Many thanks,

 

Tim McKay

 

 

Link to comment
Share on other sites

  • 3 weeks later...
7 hours ago, Tim Mckay said:

Just a bump on this... am I the only one who's seen this particular issue?

Hello,

Can you try to use this?

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  //UniPageControl1.ActivePage := UniTabSheet1;
  
  UniPageControl1.ActivePage := UniTabSheet2;

  UniPageControl1.ClientEvents.ExtEvents.Values['tabPanel.afterlayout'] :=
    'function tabPanel.afterlayout(sender, layout, eOpts) {'+
    '    var tab = this.activeTab;'+
    '    if (tab && tab.hasListeners.beforeactivate > 0) {'+
    '        tab.fireEvent("beforeactivate", tab)'+
    '    }'+
    '}';
end;

 

Link to comment
Share on other sites

  • 2 weeks later...

Thank you Sherzod, I really do appreciate it.

Your solution didn't work for me but it led to new UniGUI discoveries, so I do appreciate that.

I did try this approach on my own project, and still observed the original behavior.  It could be something else having to do with my events I am assigning too (they're in the main form, so I wouldn't think they are crossing thread boundaries but maybe it is so I will look deeper later).  So, I will look into that in the future, and come back to this point deeper then.

The main concern I had was that my users could open more than one tabs that share the same ClientDataSet, sorted one way on one Tab; sorted another way on a different tab.  So if my user went from one tab to the next, the record they were at on tab A would now appear on tab B, and to them they would think this is a problem.   For the moment, I just put in a new design convention to have unique datasets for each frame populating each tab.  It doesn't happen a lot so far so I will take the easy way out for now and solve this "right" as time becomes available.

 

Many thanks!

 

Tim

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