How to debug a Custom Property Editor in Delphi 6 (Pro)? - delphi

How can I set breakpoints and trace through a Custom Property Editor I wrote for one of my VCL derived components (Component Palette member)? The problem of course is that I want to debug code that is running in a compiled BPL while the IDE is active and is not running an active application. Setting breakpoints in the BPL source file does not do anything.
Links to a tutorial or article on debugging Custom Property Editors would be great too.
Thanks.

Tell the IDE to use itself as the host application and hit the "Run" button. It'll spawn a new instance of the IDE, and you can do whatever you need to make it hit the breakpoint you set and you can debug it as you normally would.
I'm not 100% sure where it is in D6, but in D2010, it's set under Run > Parameters... I think it's the same for D6, but like I said, I'm not sure. If you don't see that particular menu item, you should have something similar.

using OutputDebugString can helps ...not so cool as breakpoints and step by step , sure , but you can trace the flow and output value

Related

Delphi 2007 IDE layout modified after a crash

I loaded a bad PAS/DFM file (long story), which caused a GPF, after which the IDE crashed horribly. Lost my Project-related data (list of open files, etc).
Now, when I start the IDE, it always is in "run" mode. that is, it shows the breakpoints and watches and local variables, even though no program is running. Similarly, the properties are not visible unless I use F11 to bring them up. I've restarted the IDE repeatedly. Interestingly, it still can compile and run a program.
How do I reset the IDE so that it works properly?
Check your layout. It's a combo box on the toolbar. It's probably set to 'Debug Layout' instead of Default or Classic (or something else if you've setup a custom layout.)

Delphi: why breakpoints from time to time are not usable (green highlighted line on IDE)?

From time to time I lose breakpoint functionality in Delphi.
I thought this to be a Delphi 2009 issue but now I have also it in Delphi XE.
In Delphi 2009 by deleting .dproj file I made the breakpoints work again.
In Delphi XE I am not able to make breakopints appear. I have update 1 with all hotfixes applied.
Does anyone have a solution?
Debug info isn't present in the file.
Make sure that you're using the Debug configuration. (Project Manager tree, expand Build Configurations, make sure Debug is bold. If it's not, right click Debug and choose Activate from the context menu.) Make sure you then do a Build of your project, not just a Compile.
If that still doesn't work, go to Project->Options from the IDE's main menu, click on Compiling under Delphi Compiler, and check the Debugging section on the right half of the window. Make sure that Debug Information and Local Symbols are both checked. If you're trying to trace into the VCL's own source, also check Use debug .dcus (you'll want to turn this off and do a full build of your project as soon as you're done, as it gets annoying when you're debugging normally). Again, you'll want to build and not compile.
If all of the above fails, another possibility is that the code unit you have open in the Code Editor isn't the same one being seen by the compiler. Make sure you don't have multiple copies of the file on your computer in a location that the compiler might find first. If you're not sure, delete the .dcu files with that unit name and then do a build of your project, and see if the newly created .dcu is in the location you'd expect.
I found a better way.
From the Project Manager tree, right click on the project and choose "Clean" from the popupmenu.
The breakpoints reappear magically and it is a very fast method.
I suspect this happens when you have done a release build, with debug disabled. Then you switch back to debug configuration and do a compile rather than a build. The files where you can't set breakpoints correspond to those with DCUs produced by a compile with debug disabled.
Simply doing a build to re-generate all DCU files will make your breakpoints work again.
Here's one more reason to misaligned code vs breakpoint markers (blue/red "pill" in the gutter).
The editor recognices three different line endings,
CRLF (Carriage Return - Line Feed pair)
CR only
LF only
Of these, CRLF is the default in the editor.
The compiler however, doesn't seem to consider CR only as a line ending, only CRLF and LF only. Thus if your source file happens to have one or more CR only, the "blue pills" will be offset from the source.
You might have got source files with CR only EOL (end of line) character from e.g. the internet. I recall MAC OS used CR only as EOL.
To verify the EOL's in your file, you can turn on the displaying of EOL's in the editor
( Tools - Options - Editor options - Source options - Show line breaks).
The symbols look weird (see images below), but are just C on top of L for CRLF, C on top of R for CR and L on top of F for LF.
The following images show the normal EOL's (CRLF) and the EOLS's after I forced CR only for one line and LF only for another line in a hex editor. As said above, it is the CR only that offsets the break point markers from the source code.
Normal CRLF EOL's:
One line with CR only and one with LF only:
Fix
To reset all EOL's to CRLF, untick Preserve line ends in Editor Options
( Tools - Options - Editor options),
make a trivial change, so that the file is marked as modified, close the file, save changes to XYZ.pas? YES, and reopen.
Now all line endings are CRLF. Rebuilt the project and all the breakpoint balls will be in the correct locations.
Turning on remote debugging symbols did it for me (nothing else worked). Project > Options > Linking and check Include remote debug symbols.
I had the same problem with XE4. This is why I found this article a couple of hours ago. None of the above solutions worked for me. The correct solution for me - up to now - was to add "remote debug symbols" option. Strange because I don't use remote debugging. Anyway it looks OK now.
It is a bug, restarting Delphi will fix your problem.
Try remote debugging to your local PC.
Why it works: (source)
When you debug Delphi projects locally, RAD Studio does not use your RSM debug file because the compiler holds the symbol tables in memory. However, when you debug Delphi projects remotely, you must generate an RSM debug file that contains those symbol tables; otherwise, RAD Studio does not stop at your breakpoints.
Of course, you must first configure your project's "Linking" option "Map file" to "Detailed" to generate the *.rsm file. See Overview of Remote Debugging for how to get started.
I had a related problem: I lost the breakpoints in a particular file, but the other files were fine. What had happened was that I had renamed that file, but unknown to me the DCU for the old file was still being used because it was being referenced in a "uses" clause somewhere.
The solution is to manually delete all the DCUs (doing a "clean" is not enough because the old file represented by the DCU is no longer in the project) and rebuild. You will get a compile error showing the bad "uses" clauses.
Another reason for not working breakpoint could be (often tested with delphi5):
Too many procedures in a unit.
The solution is to move procedures to another unit
Although this is an old question I can confirm that this is still an issue in the current version of Delphi 10.3 Rio.
The answer above regarding line endings
https://stackoverflow.com/a/53360447/6445054
Solved the issue for me I had imported some very old Delphi code which had CR line endings
in a couple of places, as soon as I started moving code around the debugging broke completely.
The option to turn line endings on has moved slightly in Rio it's now
( Tools - Options - Editor - Source - Show line breaks).
In delphi 7 there seems to be a real bug on setting breakpoints.
I had a unit where many texts are definied in a
const constname : array[0..x] of record-type = (...);
in interface section, where record-type has some AnsiString items.
In the implementation section there are some procedures.
In some particular cases, when I set a breakpoint anywhere within a procedure, delphi does not stop at it!
Remarks: all options for debugging are set properly (as for F7 causes delphi stop at the "begin" of the program, blue dots are visible in the whole unit the line stays red while executing the app) and all DCUs that have according PAS files were deleted from all of my disks and within all folders, before I did a complete build on the whole project. So no wold files should hang around anywhere.
For testing, I renamed the PAS to another name, never ever used before, and surely nowhere else on any disk, then adapted all sources and recompiled, just to be sure that delphi and I are looking at the same PAS file - but the breakpoints did not work either.
But there another, very weird thing happened: the text consts (!) changed within my executable (not within exe file, but obviously within memory)! Those texts were checked for correctness during program start, and sometimes it complained about errors! Display of the texts in a messagebox showed, that there was changed a sinlge character within that texts, that are defined as const. For test, I tried to assign something to that consts within my code, but, as expected, compiler complained, so it cannot be an ordinary assignment that causes the change of the text. Must be a wrong pointer. Weird.
So, hours of testing followed, looking for any source code that might have set up a wrong pointer that later could cause that change in a text const. I placed the messagebox into the initialization section of the first unit within the chain of unit initialization I was able to edit, but the changed char was already there! Must be changed very early during startup of my application, then!
Finally I figured out, that the char that appeared in my texts always was an $CC - which exactly is the assembler code for INT 3, the code that delphi is using for setting a breakpoint. And when moving a breakpoint within that unit a line up or down, the position of the changed character also moves some chars left or right! And the number of characters the wrong one moved just correlated with the estimated amount of assembler coded bytes the concerned lines needed. Setting two breakpoint in lines near each other, suddenly two characters changed! When removing all breakpoints from that unit, the text remained unchanged!
So there's only one conclusion: delphi itself is changing that texts when trying to set a breakpoint and fails to do so. I was unable to get rid of this bug. None of the tips about re-synching delphi's internal bookkeeping of source and object code files did help me out!
As the concerned unit mainly consisted of {$I} lines between multiple {$IFDEF}s, for including some different, but long pascal texts, I considered delphi having problems on too long inclusions or on evaluation of conditional compiler directives. So I removed the includes and put the source text immediately into the unit, and removed the {$IFDEF}s - which compiled without errors, but setting breakpoints also changed my text constants, instead of stopping execution. All the same!
I solved this for now by splitting the unit into two units, one holding just the text consts in it's interface part, and a second one to hold the procedures. And now, without changing any compiler nor linker settings, all breakpoints do work like expected and not text is changed any more!
So, if breakpoints do not work for you, while you are sure they should, possibly delphi is the culprit and fails to set the breakpoints at the correct place. In case of it is changing just some texts, maybe that never gets to your attention. Splitting the unit helped me out, maybe that helps you, too.
If the file you're trying to set breakpoints in is part of a DLL, you need to make that DLL active by double-clicking on it in Project Manager so it turns bold, and then build it. Then the blue circles will show up next to lines where you're allowed to set breakpoints.
I solved my issue by making sure Debug was set to Local:
In my case, I was setting breakpoints in a unit that whilst open in the IDE was not part of the currently active project. Such breakpoints also show as green. IOW I was not on the right page at all.
(I discovered this after trying all of the above .)
If the project group uses packages (BPLs) ensure that none of them have any compiler warnings regarding implicitly imported units. If these exist you will only be able to step through the code via the CPU debug window.
Bit late answer but I stumbled on this problem too.
If I activated the MyPackage.bpl (bold) in the project manager with the debug configuration, then compiled it, I could see the IDE registered the debug information (blue dots on left of editor).
But when I activated my MainProject.exe (the one using MyPackage.bpl), those blue dots would disappear, indicating that the debug information is no longer present. After some head scratching, I realized that I did set up a dependency (right click on MainProject.exe -> Dependencies) on the Release configuration of MyPackage.bpl and not on the Debug configuration.
Each time I compiled MyProject.exe, it would link with the Release configuration, not the debug configuration!
So check your dependency configurations!
I had MSBuild checked under Delphi Compile (we do MS Builds). That was preventing breakpoints from working. Unchecked and it works.
By using F9 to run the app, breakpoints will work as expected. I am using XE4 and I do not know if this will "fix" prior versions of Delphi.
Since this is the best resource I found on this issue when encountering this problem with a new install of Delpi XE on a new laptop, I will just add in one more possible answer for Delphi XE.
If you are using a two monitor setup and the code editor window is on the 2nd monitor, the tooltips will not show. Works fine if the editor window is on the primary monitor. Very frustrating. May be a driver issue.

Breakpoints not working in Delphi 6 DirectShow source filter

I'm trying to debug my DirectShow source filter. I'm using Delphi Pro 6 on Windows XP along with the DSPACK component library. I'm using Skype as my host application, which I set in the Parameters option in the Run menu, for testing my source filter DLL (ax file extension). Skype runs fine and I see a stream of my OutputDebugString messages in the Event Viewer, but none of my breakpoints are ever hit. In my Project Settings I have optimizations off, stack frames on, debug DCUs on, Range Checking on, and Overflow checking on. Each time I modify my code and run a test I:
Do a full build
Unregister the DirectShow filter (regsvr32 /u)
Register the DirectShow filter (regsvr32)
Run Skype as my Host application from the IDE
When an Exception occurs, the IDE does trap it and pops up an error dialog box with the option to view the assembler code in the CPU window. However none of my breakpoints are being hit. Can anyone tell me how to get breakpoints working?
Thanks.
Along with the debug option indicated by Mason Wheeler, use a full map file. And make sure that there aren't old DCUs and BPLs in the search path.
Also, consider using EurekaLog or MadExcept - even the trial versions should be able to show you what's gong on when it blows up.
Sounds to me like you're building with debug information off, either in the project options or with a $D- switch somewhere in the code or in an include file. Check to make sure you've got debug information available.

How to debug a COM dll in Delphi?

I try to debug a COM dll (TAutoObject) in Delphi and my break point are not green.
I put my option like this :
host : c:\Program Files\Internet
Explorer\iexplore.exe
param : c:\software\test.html
My test is well lanched but no breakpoint in Delphi
what is the way to to this ?
You have to run the program which launches the COM+ object and then attach it to the process.
IE launches a sub-process which hosts non-trusted code. this is probably why your debugging settings are not working, and why attaching to the process once launched works.
Since the debugger doesn't start the file, that won't work.
IIRC you can try to "attach to process" to the process running it (iexplorer.exe), but the problem is that that doesn't allow to debug through the start of the component. (since it costs time to manually attach)
I had a different setup where I instantiated a very slightly differently compiled .ocx on a panel of a delphi app, and used that to debug. Which worked fine.d
This link Breakpoint not honored while debugging a DLL helped me debug my com dll in Delphi 5. Go to Project -> Options -> Linker -> check mark "Include remote debug symbols". I couldn't tell you why it worked. Delphi 5's help provided the following description:
Include remote debug symbols Check this if you are using remote debugging.
You also need to have integrated debugging turned on. Its on the general tab of the debugger options.
In the past what I have done is to create a separate program which invoked my COM object and used it as the target for debugging rather than the standard host. This simplifies things and also allows you to create specific repeatable tests of known issues to aid in smoke testing later.
you can also use tools like CodeSite.

How to debug Delphi project?

I'm a .NET developer, but I have got a quest - I must find errors in a Delphi project.
After opening a project (Borland Delphi 7) and trying to debug it ('Run' menu), I've noticed all debugging options are inactive (gray).
How can I make it usable?
I'm not sure why the pause button doesn't work, but I have seen Delphi 7 get "confused" and refuse to stop on legitimate breakpoints before.
Make a backup of everything, just in case you don't have the source for all of the DCUs.
Delete the project's DCUs.
Make sure you're including debug information in the project's options.
Do a full build (not just a recompile).
I hope this helps.
The debugger is always active, unless it is explicitly deactivated. Just run the application and the inactive menu items will become active. (For some options you have to have to pause the running application)
Just try pressing F8. This will run the application and pause at the first line of executable code and most of the debugging items will become active.
Hard to tell just from that description, but here are a few pointers.
Make sure you've got a project (.dpr) loaded, and not just a source (.pas) file.
Try to build the project with SHIFT-F9. When it's done, if everything compiles successfully, you'll see blue dots in the "gutter" at the left side of the text editor, showing which lines actually contain debuggable code. If you don't get any of those, go into Project Options and turn on the Debug option, then rebuild.
Once you've done that you should be able to run and debug the app.
Tools-->Debugger Options
Make sure integrated debugging is checked.

Resources