Forum > LCL

How to reference a control without explicitly naming it

<< < (2/2)

Username:

--- Quote from: Mr.Madguy on May 10, 2022, 08:03:44 am ---Yeah, same event handler can be used for different controls, if procedure declaration (i.e. number of parameters) is the same. But you need to check Sender's type then. It can be done via "is" operator.

--- 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";}};} ---  if Self is TEdit then... 
Mr,Madguy, did you mean "If Sender is TEdit"? or Self?
--- End quote ---

Mr.Madguy:

--- Quote from: Username on May 10, 2022, 08:11:20 am ---Mr,Madguy, did you mean "If Sender is TEdit"? or Self?

--- End quote ---
Yeah, wrote Self everywhere, then noticed my mistake, but failed to fix it everywhere. Self would point to control, where event handler is declared. In most cases - your form.

Username:
OK Thanks.

ASerge:

--- Quote from: Mr.Madguy on May 10, 2022, 08:03:44 am ---This operation isn't "free", because it implies built-in type check via "is" operator.

--- End quote ---
Rather very similar. This check is more gentle: allow nil.

Navigation

[0] Message Index

[*] Previous page

Go to full version