Solved

BCB5 EAccessViolation on form creation

Posted on 2004-04-07
14
976 Views
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.

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->Title = "ACS";
---->>>      Application->CreateForm(__classid(TServerForm), &ServerForm);
                 Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&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!  :)
0
Comment
Question by:c567591
  • 5
  • 4
  • 2
  • +1
14 Comments
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 10777184
Did you register the component having the TServerForm class in it?

-Lakshman
0
 
LVL 1

Author Comment

by:c567591
ID: 10777216
What do you mean?
TServerForm is the main form for the application.  I just reanamed what BCB named Form1 to ServerForm.
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 10777235
Hello there...
I guess you took the entire folder from the old pc...
Looks very strange to me too...
Suggestion:
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.
Regards,

gtokas.
0
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 10777450
>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.

-Lakshman

0
 
LVL 4

Expert Comment

by:PerryDK
ID: 10777706
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?

 
0
 
LVL 1

Author Comment

by:c567591
ID: 10777798
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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:PerryDK
ID: 10778344
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.
0
 
LVL 1

Author Comment

by:c567591
ID: 10778527
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.
0
 
LVL 1

Author Comment

by:c567591
ID: 10778762
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::
0
 
LVL 4

Expert Comment

by:PerryDK
ID: 10778912
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.
0
 
LVL 1

Author Comment

by:c567591
ID: 10779143
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.
0
 
LVL 4

Accepted Solution

by:
PerryDK earned 250 total points
ID: 10779358
mind providing code for the component so I can test it out on my system?  Just the component thats giving you problems?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now