just after properties assigned...


What is the best way to do something with visual component just after it loaded and all of its property assigned? I mean overriding SetParent or something else.

LVL 9
ITugayAsked:
Who is Participating?
 
kotikCommented:
Maybe you are looking for this:

<-- from Delphi VCL Help -->
procedure Loaded; virtual;

Description

The Loaded method allows a component to initialize itself after all its parts have loaded from a stream.

When a Delphi application loads a form from its form file, for example, it first constructs the form component by calling its Create constructor, then reading its property values from the form file, which is a stream. After reading all the property values for all the components, Delphi calls the Loaded methods of each component in the order the components were created. This gives the components a chance to initialize any data that depends on the values of other components or other parts of itself.

Note:      All references to sibling components are resolved by the time Loaded is called. Loaded is the first place that sibling pointers can be used after being streamed in.

<-- End of paste -->

You can override the Loaded method and do what anything you need.

Regards,
Kot.
0
 
PeterLarsenCommented:
Well, you dont say anything about what your are doing - e.g. design-time, run-time or component writing ??

Please give us some more details !!
0
 
kretzschmarCommented:
? agreed with peter
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
ITugayAuthor Commented:
More details.

I need to check and recalculate some properties of component. It must be done at design-time and run-time too. Text bellow is not exactly what I need but may be used as example:

type
   TMyComponent = class(TEdit)
     ...
     procedure CheckText;
  end;

procedure TMyComponent.CheckText;
begin
    if Text='' then
    begin
       Text:='some text';
       TWinControl(Parent).Width:=100;
    end;
end;

I would like to know: "Where the best place to call  procedure CheckText?". It's only sample. I only need to be sure that all properties of my component already assigned. Parent property -  for sample, it's optionally.
0
 
PeterLarsenCommented:
I think what you need is to assign your properties to procedures, like this :

type
TMyComponent = class(TEdit)
private
FMyText : string;
procedure FSetMyText(value : string);
public
 property MyText : string read FMyText write FSetMyText;

end;

procedure TMyComponent.FSetMyText(value : string);
begin
 if Value <>'' then
 begin
  FMyText:=Value;
  //or anything else you want to do
 end;
end;

Regards
Peter
0
 
ITugayAuthor Commented:
It's exactly what I need. Usually, I do it overriding method SetParent, but one guy told me that it's not right way. How I can miss Loaded?...

Thanx
Igor.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.