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.
steinonlineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MerijnBSr. Software EngineerCommented:
Delete all dcu files and rebuild all.
Check if there are any breakpoints listed in the breakpoint window (view -> debug -> breakpoints)
0
steinonlineAuthor Commented:
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('createSomeObject');
    lm.RegisterKey('994959403958340598504822');
    lm.RegisterKey('995454351896349745212301');
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.
0
MerijnBSr. Software EngineerCommented:
Probably stating the obvious, but better safe than sorry: I mean delete all dcu files of the units you have pas files too ;-)
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

MerijnBSr. Software EngineerCommented:
Hmm, can you isolate which of these 3 cause this?
0
steinonlineAuthor Commented:
yes the 3 executable lines between begin and end.
0
steinonlineAuthor Commented:
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.
0
MerijnBSr. Software EngineerCommented:
If you only call the olecreateobject, do you still have the problem?
0
steinonlineAuthor Commented:
No I do not.  Only when I make the late-bound function call to RegisterKey
0
steinonlineAuthor Commented:
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.
0
MerijnBSr. Software EngineerCommented:
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?
0
MerijnBSr. Software EngineerCommented:
Lol, we keep crossposting

If you add these lines to a new project, same problem?
0
steinonlineAuthor Commented:
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.  :)
0
MerijnBSr. Software EngineerCommented:
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?
0
MerijnBSr. Software EngineerCommented:
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!
0
developmentguruPresidentCommented:
The problem cannot be happening if the code is not called.  I would check on the CPU view and see if the call stack is skewed by the call.  You can do that by checking the ESP before you make the call and after the call has returned.  I would do this on each call.  If you find that there is a difference in the stack pointer after any of the calls returns then the call was not imported properly.  It may be as simple as looking closely at your compiler settings and making sure that the code alignment is set correctly.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sinisa VukSoftware architectCommented:
Try this:
- go to Project/Options menu
- select Compiler tab
- uncheck Optimization (code generation)
- check Use Debug DCUs
- rebuild project: Project/Build ....
0
steinonlineAuthor Commented:
Thank you so much for your fresh eyes and brain!!
0
steinonlineAuthor Commented:
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!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.