Forum > LCL

Does Lazarus support event bubbling, event propagation?

(1/3) > >>

tu:
I have a navigation sidebar as in attached image. I want all click event on Label and Inner Panel buddled to Outer Panel click event handler.

I tried but it seems event bubbling does not work.

Thank you very much,

Remy Lebeau:

--- Quote from: tu on November 16, 2024, 05:36:29 am ---I have a navigation sidebar as in attached image. I want all click event on Label and Inner Panel buddled to Outer Panel click event handler.

--- End quote ---

Simply assign the same event handler to each object. You can use the Sender parameter to know which object received the click, if needed.


--- Quote from: tu on November 16, 2024, 05:36:29 am ---I tried but it seems event bubbling does not work.

--- End quote ---

It would help to see what you actually tried.

tu:
Yep, I assigned the same event handler to each control and it worked. But it seems too many duplicated code  ::)

Is there anyway better? What is the best way we should use to handle event propagation with deep nested controls in LCL?  :)

Thaddy:
Do you want propagation or demotion?
Both can be done in code, the latter being much slower, because propagation goes from the containing window down to a nested control.

tu:

--- Quote from: Thaddy on November 16, 2024, 11:32:24 am ---Do you want propagation or demotion?
Both can be done in code, the latter being much slower, because propagation goes from the contaning window down to a nested control.

--- End quote ---

Can you give me some example code for both usecase?  Thank you so much :)

Maybe I need propagation event or bubbling event because I'm building a navigation sidebar using deep nested controls.

For example:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TPanel (Level 1) > TPanel (Level 2) > TLabel (Level 3) TPanel (Level 1) > TPanel (Level 2) > TPanel (Level 3) > TLabel (Level 4) 
When click on child control I want to bubble event to Level 1 event handler.

Navigation

[0] Message Index

[#] Next page

Go to full version