Link to home
Start Free TrialLog in
Avatar of StevenB
StevenB

asked on

Design time compoment problem

 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;
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of StevenB
StevenB

ASKER

 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
Avatar of StevenB

ASKER

 or rather ...

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



  ;o)
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 ;-)