Multiple copies of a unit lazarus / 9-Editor ---------------------------------------------------------------------- iru · 2016-01-31 20:57 Gentlefolk, Environment: Laz 1.4.4, Linux Mint 17. I have a small program with multiple units. Working my way through the usual write-code/debug seuence with breakpoints I find I have multiple copies of a unit displayed in the IDE. One, the original say named "UnitTeam" and a second "UnitTeam (2)". Different code in each version, different debug breakpoints. I have also lost code by saving the (2) version. Only "unitteam.pas" exists in the file system. What is going on? Any help appreciated, Ian. With breakpoints in ---------------------------------------------------------------------- staratel20 · 2016-01-31 21:09 Never dive to this situation, because have a habit to point mouse on tab-head and look to the hint(with full path) - what exactly unit I work with. ---------------------------------------------------------------------- iru · 2016-02-01 01:12 Gentlefolk, I did some more research through the forum and came upon an entry "how have the same unit in two tabs". A mixture of English and Spanish/Portugese (real and translated) of Sep 12 2015. It contained the following information: "Also there is a bug in the IDE, if the project file becomes corrupt the IDE may open the same file in 2 tabs in one window. But that can not be done intentional. (I have seen it happen, but I was never able to force it happen)". Is this my problem??? There was also a code update for the Editor/IDE config file. I will have a good look at things when I get home..... Ian ---------------------------------------------------------------------- Martin_fr · 2016-02-01 03:09 If you  have 2 or more files of the same name, but in different folders, then they are different units. Only one can be compiled into the exe. But the others can be open, and breakpoints in any of them are "forwarded" (strange, but unavoidable) If (on linux) you use symbolic links, the IDE will think you have 2 files. Even it is only one. You can check your lpi and lps files. How often is the unit listed? And each time it is listed look at the path. ----------------- The basic is, unless you know a lot of details, keep all your units for one program in one folder. Units that are shared with other programs go in packages (and for each package one folder) No 2 units should have the same name. If you open backups (ok), which are duplicates, then make sure, you do - not edit them - not set breakpoint in them ---------------------------------------------------------------------- iru · 2016-02-01 04:12 Thanks for the detailed response. All files are in one folder/directory. File name is unique. No symbolic links. I will check the lpi and lps files when I get home tonight. Thanks, Ian ---------------------------------------------------------------------- Martin_fr · 2016-02-01 05:33 A bit of background: FPC (during compilation with debug info) puts into the final exe, the name and path of each unit (the path in which fpc found the unit). GDB can and does report this back to the IDE. But sometimes GDB can not find a unit, if the IDE asks for it, even if the IDE gives the full and correct path. That would prevent breakpoints from being set, so the IDE only uses the filename without path in order to set breakpoints. (because that always works). In theory that should be save. The way units works (an linking) it is not possible two have to units of the same name (not even in different folders). But it has an unwanted side effect. Assume your project (or package) is in C:\pascal and has a unit "C:\pascal\foo.pas". Now if you open any file called foo.pas from anywhere else in your filesystem (or sym linked), and set a breakpoint in it, the the IDE tells GDB to set the breakpoint in "foo.pas". If that breakpoint is hit, GDB reports C:\pascal\foo.pas, and the IDE opens this (a 2nd foo.pas). And that is how you get 2 of them open. If the foo.pas that was NOT C:\pascal\foo.pas, was similar (a backup, a copy of the same unit in a different project), you may have been unaware that it was the wrong file. And it can be more complex. If you modified the wrong settings (search path) in the options, then you may have had C:\pascal\foo.pas open. But fpc did find a different copy and compile that wrong copy into your exe. Example, afaik, if you "save as" to a new location (to make a copy) the new location can be added to the search path. And that is how fpc finds that copy then. There may be more ways to get that, but those are some examples. ---------------------------------------------------------------------- iru · 2016-02-01 09:33 Thank you once again for the detiled response, I was walking home from work and thinking about this when I thought of a possible cause of this problem and I think your previous response sort of fits in with the following. I created the project /home/iru/project/LAZ. The project files got created in /home/iru/Projects/LAZ. This is not what I wanted so I created a folder/directory /home/iru/projects/LAZ/AVEL-1. I cut and pasted the files from /home/iru/Projects/LAZ to AVEL-1. I then opened the project from /home/iru/projects/LAZ/AVEL-1. So somewhere deep down inside LAZ it may know of /home/iru/Projects/LAZ/unitteam.pas (which has been deleted) and also know /home/iru/Projects/LAZ/AVEL-1/unitteam.pas. I will save the project again to a new directory. I will also have a good read of th previous responses. Thans again, Ian. ---------------------------------------------------------------------- Martin_fr · 2016-02-01 14:17 try to use "publish project" from the "project" menu. That should give you a clean(er) copy. ---------------------------------------------------------------------- iru · 2016-02-05 10:24 Thanks, for all the help. Tidied things up: Created a new project, copied the original files into the project directory, opened each file and "added" it to the project. No further problems. Once again, thanks, Ian.