Solved

Component Properties read component

Posted on 2001-08-06
5
255 Views
Last Modified: 2010-04-06
Another properties question.
I have a property to which I can assign a checkbox.
When the application starts I want to check this property and read its checked value.
So I test to see if the checkbox property is <> nil, in my components constructor, this always returns false. Later when the project is running I can read the checkbox without problems. Is this because my component is created before the checkbox?
0
Comment
Question by:sorentop
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
nnbbb09 earned 50 total points
ID: 6357413
Hello,

Delphi creates the components on a form in the order in which they were added to the form, so it is very likely that your component could be created before the checkbox exists, so it is always a good idea to ensure it exists by using "assigned" or checking for nil. If you need to run initialization code for your component that depends on all controls on the form being present then override the Loaded procedure.

Jo
0
 

Author Comment

by:sorentop
ID: 6357426
Hi again

Is that something I can do from the component ?
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 6357636
Your component has most likely overridden the Create constructor already.  Overriding the Loaded procedure is very similar.

In the component class's Public section add:

procedure Loaded; override;

And in the implementation section you add:

procedure TMyClass.Loaded;
begin
     ReadCheckBoxCheckedValue;
     inherited;
end;

0
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6358523
Hello,

The Loaded procedure is declared in TComponent and should be overriden in your class as MannSoft has shown. What happens is once all the components on your form have been created from the stream, each Components Loaded procedure is called.

Incidentally, if you are linking two components together at design-time using the Object Inspector then you will need to add some code to your component manage the deletion of the checkbox, otherwise you may get access violations. To do this you need to override the Notify procedure eg :

protected
   procedure Notification(AComponent: TComponent;
 Operation: TOperation); override;

procedure TMyClass.Notification(AComponent: TComponent;
 Operation: TOperation);
begin
 inherited Notification(AComponent, Operation);
 if (Operation = opRemove) and
    (AComponent = MyCheckbox) then MyCheckbox := nil;
end;

This means your component will be notified everytime a component on the same form is deleted. If it is the checkbox then set your Checkbox property to nil.

Jo
0
 

Author Comment

by:sorentop
ID: 6358684
OK I did not know the loaded procedure.

Also thanks MannSoft for your example.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
indy Tmemory stream non latin charcter issue 2 98
code issue 8 100
Graphics32 under Delphi 10.1 Berlin 2 36
how to change, disabled button color FMX ? 1 14
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now