zebada
asked on
Deleting linked components
I have component1 that has another component2 as a published property.
In the IDE:
I set this property of component1 so that it links (points to) component2.
So far so good.
Now, when I delete component2 the property in component1 still points to component2 and causes serious problems with the IDE reporting memory access violations.
Do I need to clear the property in component1 that points to (the now deleted) component2.
And if so how do I do that, do I need component2 to have knowledge of component1?
In the IDE:
I set this property of component1 so that it links (points to) component2.
So far so good.
Now, when I delete component2 the property in component1 still points to component2 and causes serious problems with the IDE reporting memory access violations.
Do I need to clear the property in component1 that points to (the now deleted) component2.
And if so how do I do that, do I need component2 to have knowledge of component1?
ASKER
Here's sample code that demonstrates the problem:
1. Place both components on a form, from the "My stuff" palette page.
2. Set the property "other" of Image1 to Other1.
3. Delete Other1 from the form.
4. BANG!
unit Image1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TOther = class(TImage)
end;
TImage1 = class(TImage)
private
Fother: TOther;
procedure Setother(const Value: TOther);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property other: TOther read Fother write Setother;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('My Stuff', [TImage1,TOther]);
end;
{ TImage1 }
procedure TImage1.Setother(const Value: TOther);
begin
Fother := Value;
end;
end.
1. Place both components on a form, from the "My stuff" palette page.
2. Set the property "other" of Image1 to Other1.
3. Delete Other1 from the form.
4. BANG!
unit Image1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TOther = class(TImage)
end;
TImage1 = class(TImage)
private
Fother: TOther;
procedure Setother(const Value: TOther);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property other: TOther read Fother write Setother;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('My Stuff', [TImage1,TOther]);
end;
{ TImage1 }
procedure TImage1.Setother(const Value: TOther);
begin
Fother := Value;
end;
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
Perfect :)
A piece of code would be nice. Don't you think so?
Tchau,
Reginaldo