Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Component Properties read component

Posted on 2001-08-06
5
Medium Priority
?
276 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
[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
5 Comments
 
LVL 3

Accepted Solution

by:
nnbbb09 earned 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

664 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