[SOLVED] Which DUPLICATE form did I click? lazarus / 31-LCL ---------------------------------------------------------------------- JCobb · 2018-03-27 07:04 Hello! I'm writing some code that creates multiple copies of a form at runtime.   These are duplicates of an existing form listed in the "auto-create" section of Project Options (in other words I've pre- built the form and I'm just duplicating it). Everything I've been doing works great until I click an image object on one of the forms.  I've no idea which form received the click event.  As far as the program is concerned all the duplicate forms have the same name.  I've tried creating forms with different values in the "tag" property but to no avail. Keep in mind the image I click is contained in a flowPanel on the form. How can I tell which form is receiving the mouse events? Thanks in Advance. Jeff ---------------------------------------------------------------------- Thaddy · 2018-03-27 07:57 https://www.freepascal.org/docs-html/rtl/system/tobject.unitname.html Put that in the onclick event and you will detect from which unit it comes. Easy. Unless you put multiple forms in the same unit (bad!) of course. ---------------------------------------------------------------------- Fahmy Rofiq · 2018-03-27 08:07 Duplicate forms always have different names. A number automatically added on the end of "Name" property. Please look at attachment. ---------------------------------------------------------------------- Thaddy · 2018-03-27 08:12 Quote from: Fahmy Rofiq on March 27, 2018, 10:07:23 amDuplicate forms always have different names. A number automatically added on the end of "Name" property. Please look at attachment. I am afraid that is not  true at all.... You can have unit1.Tform1 and unit2.Tform1 etc....You can even have multiple instances of the same form class....(much worse) So it is better to check the unit name during debugging so you definitely know where the form is that handles the event. At least you have a clue then. Although it is always better to do your naming properly: the question starts with really, really, extremely bad programming practise of course. But it IS allowed and possible. If you need the instance, you can also use https://www.freepascal.org/docs-html/rtl/system/tobject.equals.html ---------------------------------------------------------------------- Fahmy Rofiq · 2018-03-27 08:27 Quote from: Thaddy on March 27, 2018, 10:12:46 amQuote from: Fahmy Rofiq on March 27, 2018, 10:07:23 amDuplicate forms always have different names. A number automatically added on the end of "Name" property. Please look at attachment. I am afraid that is not  true at all.... You can have unit1.Tform1 and unit2.Tform1 etc....You can even have multiple instances of the same form class....(much worse) So it is better to check the unit name during debugging so you definitely know where the form is that handles the event. At least you have a clue then. Although it is always better to do your naming properly: the question starts with really, really, extremely bad programming practise of course. But it IS allowed and possible. Yeah, i was thinking that TS just duplicating form object from the same unit.  So manually handling the name of form could resolve the problem. But if TS duplicating the UNIT, thats different story. ---------------------------------------------------------------------- Thaddy · 2018-03-27 08:53 Quote from: Fahmy Rofiq on March 27, 2018, 10:27:28 amBut if TS duplicating the UNIT, thats different story. That is also possible... but then the compiler throws a duplicate identifier error, so he would have known because that will not compile at all: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {%fail}program testpaths;{$mode delphi}uses unit1 in '/home/pi/somepath/unit1.pas', unit1 in '/home/pi/someotherpath/unit1.pas';beginend. Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i testpaths.pas(4,89) Error: Duplicate identifier "UNIT1" ---------------------------------------------------------------------- JCobb · 2018-03-27 15:38 FOUND IT...   To refer to a particular instance of a DUPLICATE form you use the keyword SELF.... Duh... I was expecting something like "THIS"... Thanks for all your help.  Much appreciated (and fast)! Jeff