Search code examples
delphidebuggingaccess-violationvcldelphi-10.3-rio

How do I debug VCL errors?


I don't know how you do it, but when I work on a new component, in order to test it, I create it manually at runtime and assign it a parent, so that I don't have to install it every time... Now I'm done and it works perfectly when I run it this way. But after I install it in the VCL and I want to put it on a Form, I get an 'access violation' error from somewhere in the constructor. How can I debug it if I don't have access to run it line by line to see where it happens and in which conditions ?


Solution

  • When you have your component installed in the IDE, restart the IDE and open the component run-time package project (it must have been compiled in a debug build configuration). Then go to the IDE "Run" menu, select the "Parameters" submenu, and in the "Host application" field, enter the full path of the Delphi IDE (Something like "C:\Program Files (x86)\Embarcadero\Studio\21.0\bin\bds.exe"). Then hit F9 to run your project (the run-time package) under the debugger.

    This will launch another instance of the IDE. With this instance, create a new VCL project and drop your component. The first instance will popup when hitting the Access Violation you mentioned.

    Of course, before hitting F9, you can put any breakpoint you like and then single step through your code to find out the error.

    Likely, you can debug the component's design-time package this way, too.