Solved

Design time compoment problem

Posted on 2001-07-06
4
303 Views
Last Modified: 2012-06-27
 I have a component decended from TComponent (Component A). One of its published properties is another component (Component B). At design time I can select a component from the form for this property in the object inspector.

  The problem is this:

  When I delete Component B from the form, the refernce remains in Component A. This upsets Delphi enormously and causes all sorts of access violations. I cannot alter the code for Component B (it could be a VCL object for example) so what is the correct solution for this problem.

  Somehow when Component B is deleted, Component A must Nil its reference. Perhaps I should listen for a message in Component A? if so which one? Maybe there is something I can do with csDesigning flag? Any ideas?



  An Example :

type
  TComponentA = class(TComponent)
  private
    fComponentB : TComponent;
  published
    property ComponentB : TComponent read fComponentB write fComponentB ;
  end;
0
Comment
Question by:StevenB
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 6258556
there is a notification method,

you've to fill out this method like

if (AComponent = MyPropertyComponent) and
   (action = opremove) then
  myPropertyComponent := NIL;

didn't have the correct header-syntax of the methjod in mind, look at the help amnual for this

meikl
0
 
LVL 4

Author Comment

by:StevenB
ID: 6258578
 brilliant, so the solution is this:


type
  TComponentA = class(TComponent)
  private
    fComponentB : TComponent;
  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  published
    property ComponentB : TComponent read fComponentB write fComponentB ;
  end;


procedure TEntSMSTextMessageEdit.Notification(AComponent: TComponent; Operation: TOperation);
begin
  If (AComponent = fComponentB) and (Operation = opRemove) then fComponentB := Nil;
end;



  Thanks meikl, fastest solution ever :o)

  Steven
0
 
LVL 4

Author Comment

by:StevenB
ID: 6258593
 or rather ...

procedure TComponentA.Notification(AComponent: TComponent; Operation: TOperation);
begin
 If (AComponent = fComponentB) and (Operation = opRemove) then fComponentB := Nil;
end;



  ;o)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6258634
well, glad to helped you,
sorry that i didn't had the correct syntax in mind,
(have no delphi available at the moment)

but as i see, you get it work

good luck again

meikl ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

12 Experts available now in Live!

Get 1:1 Help Now