Solved

Design time compoment problem

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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