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;
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
or rather ...
procedure TComponentA.Notification(A Component: TComponent; Operation: TOperation);
begin
If (AComponent = fComponentB) and (Operation = opRemove) then fComponentB := Nil;
end;
;o)
procedure TComponentA.Notification(A
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 ;-)
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 ;-)
ASKER
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.Not
begin
If (AComponent = fComponentB) and (Operation = opRemove) then fComponentB := Nil;
end;
Thanks meikl, fastest solution ever :o)
Steven