Solved

Design time compoment problem

Posted on 2001-07-06
4
302 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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