steinonline
asked on
Delphi 7 Debugger out of step with source code?????
Experts I am having a really strange issue suddenly. When I run my application in the delphi environment, the debugger stops on a random line of code with no breakpoint set. Additionally, the blue compiler dots in the left gutter are displayed on lines with no code at all. Outside the environment the compiled program is completely haywire. I have never seen anything like this before. Also I am running Windows XP as a virtual machine on an Apple computer. Any thoughts on what could be the problem, and what I can do to solve this issue would be greatly appreciated. I have removed the "bad" unit from my program, copied and pasted the source code into a new unit, saved that unit then added it back to my program. Now the same thing is happening only in that unit, and on a totally different line of code. It is like no matter what, execution goes to this spot. I am baffled, and have a deadline that is going to come and go if I can't get a handle on what's going on here.
ASKER
I have already done that two times. I have found however that the problem is coming from a specific place. I am using a .NET assembly in a COM interop scenario. If I remark out these lines of code, the problem completely resolves itself.
uses
ComObj
var lm:Variant;
begin
lm:=olecreateobject('creat eSomeObjec t');
lm.RegisterKey('9949594039 5834059850 4822');
lm.RegisterKey('9954543518 9634974521 2301');
end;
if these 3 lines of code are present anywhere in my program, the debugger, and the flow of execution in the compiled program is haywire.
uses
ComObj
var lm:Variant;
begin
lm:=olecreateobject('creat
lm.RegisterKey('9949594039
lm.RegisterKey('9954543518
end;
if these 3 lines of code are present anywhere in my program, the debugger, and the flow of execution in the compiled program is haywire.
Probably stating the obvious, but better safe than sorry: I mean delete all dcu files of the units you have pas files too ;-)
Hmm, can you isolate which of these 3 cause this?
ASKER
yes the 3 executable lines between begin and end.
ASKER
I believe wholeheartedly that the problem is due to the 3rd party component that I am using. I am not going to name them on here unless they fail to provide me with a valid solution. However if you can shed any light at all as to why this is happening, the points are yours.
If you only call the olecreateobject, do you still have the problem?
ASKER
No I do not. Only when I make the late-bound function call to RegisterKey
ASKER
Actually I don't even have to execute these lines. I can put them in an obscure place in my program and never execute them. This misalignment occurs if these lines are merely present.
You first need to make the problem as small as possible, hence my question.
Did you try with just olecreateobject?
If that works OK, if you add a single to RegisterKey, if that fails again, can you call anything else from the .net assembly, and does that fail as well?
Did you try with just olecreateobject?
If that works OK, if you add a single to RegisterKey, if that fails again, can you call anything else from the .net assembly, and does that fail as well?
Lol, we keep crossposting
If you add these lines to a new project, same problem?
If you add these lines to a new project, same problem?
ASKER
No I haven't tried to simplify it to that degree. The problem isn't with the .NET call failing. It is working correctly. It's the random branching of execution and the misalignment of source code vs compiled unit that is so troubling about this. I can pare it down to very small but not sure the symptoms will manifest in the same way, and even if so, it doesn't solve the problem, but merely reinforces that I have located the issue. This is bizarre and frustrating. Thank you so much for taking your time to help me. I appreciate it very much. :)
If you reduce the problem to degree changes are big you can solve the problem, or find a work around, so I do advice you try to simplify it. Can you see any of the symptoms with these 3 lines in an empty project?
I'm about to go offline, so here are the steps I would take, maybe it helps you.
If you can not reproduce the issue in a new project: go back to your original project and make it as small as the new project. Take out anything besides the 3 lines to make it go wrong. Check regularly if it still fails while breaking away code. If you get to the point both projects are the same and there is still a difference, check the project options. Search for any difference between the two.
If you can reproduce the issue in a new project: check surrounding code, did you put anything in your uses to get the 3 lines compiling (like a tlb file). If yes, makes those files smaller too. Take out everything which is not needed to compile (including compiler directives, etc). Check regularly if the problem still exists while doing so.
Good luck!
If you can not reproduce the issue in a new project: go back to your original project and make it as small as the new project. Take out anything besides the 3 lines to make it go wrong. Check regularly if it still fails while breaking away code. If you get to the point both projects are the same and there is still a difference, check the project options. Search for any difference between the two.
If you can reproduce the issue in a new project: check surrounding code, did you put anything in your uses to get the 3 lines compiling (like a tlb file). If yes, makes those files smaller too. Take out everything which is not needed to compile (including compiler directives, etc). Check regularly if the problem still exists while doing so.
Good luck!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Try this:
- go to Project/Options menu
- select Compiler tab
- uncheck Optimization (code generation)
- check Use Debug DCUs
- rebuild project: Project/Build ....
- go to Project/Options menu
- select Compiler tab
- uncheck Optimization (code generation)
- check Use Debug DCUs
- rebuild project: Project/Build ....
ASKER
Thank you so much for your fresh eyes and brain!!
ASKER
Developmentguru no offense you are wrong about the fact that this cannot be happening if the code doesn't execute. It is happening without ever executing a single line of it. If I remove it the problem goes away. However you are correct about checking the record-field alignment in compiler settings. It was set to Byte alignment instead of 4 Byte (default) because years ago it had to be that way to read a binary file written in a QuickBasic program. I switched the record field alignment and voila!!! Thanks for the tip. You got me out of the box!
Check if there are any breakpoints listed in the breakpoint window (view -> debug -> breakpoints)