We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


BCB5 EAccessViolation on form creation

c567591 asked
Medium Priority
Last Modified: 2007-12-19
I am using BCB5 enterprise, on a project that worked on my old PC.
This is on my new PC and is driving me nuts.
I am getting an EAccessViolation at the point of creating the form, before my app actually does anything of mine.
This is a fresh load.  All BCB patches have been applied.  This is on WinXP, the old PC was Win2000.
I have the same components loaded that I had before.
I can make a new project just fine, so I created a new project, added these files, and get the same result.  :(
The new compiled size of my app is ~1/5 or 1/6th the size it should be, or at least the size that it was.  
I have tried static and dynamic linking.
I have cleared all the usual suspects that BCB has troubles with.
I have tried a full build, deleting all obj files.
It is a medium size project with a lot of components, so starting over is not an option.

                 Application->Title = "ACS";
---->>>      Application->CreateForm(__classid(TServerForm), &ServerForm);
        catch (Exception &exception)
        return 0;
Stepping into this gets to here:
//In forms.hpp
      /* TCustomForm.Create */ inline __fastcall virtual TForm(Classes::TComponent* AOwner) : TCustomForm(
            AOwner) { }

What is going on?
Help!  :)
Watch Question

Did you register the component having the TServerForm class in it?



What do you mean?
TServerForm is the main form for the application.  I just reanamed what BCB named Form1 to ServerForm.
Hello there...
I guess you took the entire folder from the old pc...
Looks very strange to me too...
Start a new project with an empty form, run it and save it in the same directory.
Remove EVERYTHING from the new project.(cpp,res,etc.)
Add the source files of the old project save and try to run again..
I think that it will work.
If not then something is wrong at your source files caused from the move.
At least for me the problems solved that way.

>It is a medium size project with a lot of components, so starting over is not an option.

As you mentioned this,I just wanted to confirm if all these components are registered on your new machine.


The access violation is more than likely (99%) being caused by something in your constructor of TServerForm.

Set a break point on the first line of the construtructor. keep hitting F8 until it throws the exception.  Make a note of the line number.  If that line is a function call or method call.  Put a break point in the first line of that function and repeat process until you find the actuall line that is causing the exception to be thrown.

Just knowing that
Application->CreateForm(__classid(TServerForm), &ServerForm);

is throwing the exception is of little use.  All we can tell from that the exception could be anywhere in the code that creates the form.  So first step is try to dig deeper and figure out exactly where its throwing the exception in this call.  The constructor of TServerForm is the next logical place to go from there.

if you don't have any code in the constructor for this form.  As lakshman has said its probably due to the fact that all of the components are not registered on your new machine.  Are you using any third party componets or componets you created your self and added to the component pallet?



As far as I know all components are registered properly.
I know for sure that the 3 types that I use most are all registered and can be used in other projects.

Stepping into this line in WinMain gets to here:
//In forms.hpp
     /* TCustomForm.Create */ inline __fastcall virtual TForm(Classes::TComponent* AOwner) : TCustomForm(AOwner) { }

It stops here in forms.hpp and will go no further.
It never gets to the OnCreate event.

I was talking about the constructor of the form.

should look like
__fastcall TServerForm::TServerForm(TComponent* Owner)
  : TForm(Owner)
  //set break point on first line of some code.
  //some code

This is completly separate topic...but FYI...NEVER EVER USE the OnCreate or OnDestroy events in c++ builder you should only be using the constructor and destructor of your form.  If you have code in the OnCreate put it in your constructor which likes like the code above it was created automatically for you.  If you code in the OnDestroy event place it in the destructor.  You'll have to put this in your header file
virtual __fastcall ~TServerForm();

and put this in your .cpp file
__fastcall TServerForm::~TServerForm()

The reason you should never use the OnCreate or OnDestroy events is that the OnCreate event can actually get created before your class instance is created.  Events are triggered by the message queue.  Likewise the OnDestroy event can get called after you class instance has been destroyed.

The only reason the OnCreate and OnDestroy events are provided is because the are reminants of Delphi.  Pretty much all VCL code and components you have on your component are actually written in Delphi.  Delphi was created first then C++ Builder came along and was configured so that it could use the overwhelming amount of VCL code and componets that was already written in Delphi.

Sorry for the long side step but it is important you don't use those events when using C++ Builder.  At any rate once you put your OnCreate code in the constructor and OnDestroy code in the destructor set a break point on the first line of the constructor and step through it until you find where it crashes.


Ok stepping into the constructor....
Stops at the same point.

__fastcall TServerForm::TServerForm(TComponent* Owner)
    : TForm(Owner) //With breakpoint here, we stop at that line in forms.hpp
  return;   //Breakpoint here never occurs because it doesn't get this far.

//In forms.hpp
     /* TCustomForm.Create */ inline __fastcall virtual TForm(Classes::TComponent* AOwner) : TCustomForm(AOwner) { }

It stops here in forms.hpp and will go no further.

There is nothing remaining in my OnCreate handler, it has been all commented out.


Ok, I made a "test" project and added 1 by 1 each component type and named them appropriately.  I determined which of my components that is misbehaving, now why in the world would it misbehave like this?
I removed it from the user component library bpl and rebuilt it.  I then added it back in and rebuilt it.  Still no luck.  However it works in design mode just fine.
This component *was* working just fine before... ::grumble::

The component you are using is a component you created or a third party created; correct?  It is also installed and showing up on your component palette?

If your refering to the dclusers library find try reinstalling that package.


It is installed and showing on the palette.

I did reinstall dclusers:
Removed component.
Rebuilt & reinstaled dclusers
Added component
Rebuilt & reinstaled dclusers

still no luck.

It does a bit of string manipulation, nothing edgy or fancy, and like I said, it (the component) works inside the IDE.
Unlock this solution and get a sample of our free trial.
(No credit card required)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.