5

This is an odd behaviour by my D2006 as it happens sometimes only. I have a project I want to debug. The file I want to debug is named 'Main.pas'. I have another unrelated project with the same Unit name and sometimes the Debug prompt me the wrong Main file instead of the Main unit from the current project. This have happened to me with other files with the same name. I can't debug then as the debug keys don't work (they just don't do anything). Do you have experienced the same problem? How can I fix it?

Thanks.

Averroes
  • 4,168
  • 6
  • 50
  • 63
  • Happens too in Delphi 2009 for me if I work on two projects where units have the same name - if I open a file which belongs the other version, the debugger starts to use the other versions source directory instead of the directories of the open project (dpr) file. – mjn Apr 09 '10 at 10:47

3 Answers3

5

Do you use relative paths?

If yes, I found out it helps to set the working directory to my projects directory y loading a file from my projects dir using File->Open. The navigating and loading apparantly sets the working dir, fixing the case where you THINK you are using paths relative to your project, but delphi interprets them relative to the working dir of the IDE. Close all other tabs first though, to avoid mistakes. Since the delphi compiler is a dll, it interacts deeply with the IDE, and probably has access to which files are opened. (it can compile unsaved files!)

If not, it might a freak occurance, but still have the same origin. Developing a habit to first close other files (right click on tab->close all other), and fixate the working dir (with the load unit via file-Open workaround) might help.

I've the feeling the BDS series of IDEs seem to suffer from this more than the classic ones, but the problem existed in the classic ones too. Could be as simple as using more fancy opendialog options in BDS, increasing the chance on working dir change.

update Also only opening projects when no other projects are open helps. So always click the old project before opening the new, and don't click a project in the windows explorer if the IDE is open with another project loaded.

Delphi XE still suffers from this

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
  • i believe this is absolutely correct. now when i open an unrelated file, i never use File, Open...i drag the file from explorer to delphi or let explorer decide how to open the file. – X-Ray Apr 08 '10 at 21:25
  • +1. I discovered the File->Open trick in my D2006 days and got used to it. I have nevered bothered to check if it is still necessary in D2007. – Uli Gerhardt Apr 09 '10 at 09:18
  • Sorry, I don't understand this answer. What exactly should we be doing to avoid this problem, and if it does happen, what can we do to fix it? The only way I've found to fix is to rename the "wrong" folder. – dan-gph Feb 13 '12 at 03:00
  • The problems noted are the result of the working dir of the BDS IDE not matching the project directory. The solution is to load any file using the file-open dialog from the project directory. This resets the working directory. Since relative parts are relative to the working dir (though that is assumed to be the same as the project dir), in projects with relative paths you notice this sooner. – Marco van de Voort Feb 17 '12 at 13:51
  • Thanks, Marco. That doesn't work for me. I must have a different problem. I have the same project checked out twice, sitting side by side. If I ctrl-click on an identifier, Delphi opens the unit from the other project. – dan-gph Feb 20 '12 at 08:54
1

I have run into that too, and now I tend to give files unique names, like instead of Main.pas, it might be ProjectNameMain.pas

Check your Library paths and Browsing paths in the Environment Options

jasonpenny
  • 2,999
  • 1
  • 24
  • 23
  • If you use this project as the starting point for a new (or parallel) project, all files need renaming :P - Imagine how it would be to have SysUtils50, SysUtils60, SysUtils70 and so on in the RTL, and with every new Delphi version developers need to fix all references to RTL unit names :) – mjn Apr 09 '10 at 10:44
0

Take a look at the output and DCU directories of the project. You're probably picking up an old DCU from a shared DCU directory. Clear out the DCUs and re-build.

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62