Solved

Design time compoment problem

Posted on 2001-07-06
4
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

628 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