Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:02:02+00:00 2026-06-09T05:02:02+00:00

I have a unit which has a variable of TComponent, I create this component

  • 0

I have a unit which has a variable of TComponent, I create this component on Initialization of the unit like following :

var
  XComp: TComponent;
.
.
.
.

initialization
begin
  XCom := TComponent.Create(Application);
end;

after installing the unit when I close Delphi it gives me an Access Violation error message (EAccessViolation)

but when I changed my creator to be as following

initialization
begin
  XCom := TComponent.Create(nil);
end;

everything went fine…I would like to know the difference? and what is the better?

note : the error only appears when closing the delphi (means at design time).

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:02:06+00:00Added an answer on June 9, 2026 at 5:02 am

    Basically both are allowed and it should not result in an AV even if you have code like this:

    MyComp := TMyComp.Create(Application);
    try
      {...}
    finally
      MyComp.Free;
    end;
    

    This is because a properly coded component will remove itself from its owner’s components list when it is being destroyed.

    I think the problem here might be that the component was already freed by the application object and later on some code tries to access it. Maybe there is a finalize section in your code, that does it? Or you might have mixed objects and interfaces and reference counting got you.

    To debug your problem, you could run the IDE in the debugger by setting your package’s “host application” to Delphi (C:\Program Files\\BDS\\Bin\bds.exe).
    and set a breakpoint in your component’s destructor. That way you will find out where it is being freed and also where the AV occurs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following actor for which I would like to create unit tests
I have a Unit testing problem where a class has a static variable which
I have some classes(call it Class A) which I would like to unit test
I have a list: list<Unit *> UnitCollection; containing Unit objects, which has an accessor
I have a class which has some unit tests, but when I am running
I have an open source library which has plenty of unit tests that compare
This must be a Delphi bug... I have a unit which is the basis
I have a query like the following: Select new mypackage.MyClass( u, max(sc.serviceDate)) from Unit
I have a Unit which has a UnitType and an Organization. I have a
I have the following datatable, which has Units information. The Units have a surface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.