Avatar of steinonline
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.
Microsoft DevelopmentDelphi

Avatar of undefined
Last Comment
steinonline

8/22/2022 - Mon
MerijnB

Delete all dcu files and rebuild all.
Check if there are any breakpoints listed in the breakpoint window (view -> debug -> breakpoints)
ASKER
steinonline

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.
MerijnB

Probably stating the obvious, but better safe than sorry: I mean delete all dcu files of the units you have pas files too ;-)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
MerijnB

Hmm, can you isolate which of these 3 cause this?
ASKER
steinonline

yes the 3 executable lines between begin and end.
ASKER
steinonline

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
MerijnB

If you only call the olecreateobject, do you still have the problem?
ASKER
steinonline

No I do not.  Only when I make the late-bound function call to RegisterKey
ASKER
steinonline

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
MerijnB

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?
MerijnB

Lol, we keep crossposting

If you add these lines to a new project, same problem?
ASKER
steinonline

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.  :)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
MerijnB

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?
MerijnB

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!
ASKER CERTIFIED SOLUTION
developmentguru

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Sinisa Vuk

Try this:
- go to Project/Options menu
- select Compiler tab
- uncheck Optimization (code generation)
- check Use Debug DCUs
- rebuild project: Project/Build ....
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
steinonline

Thank you so much for your fresh eyes and brain!!
ASKER
steinonline

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!