I overrided the AfterConstruction method in my component in order to call
OnCreate event handler if assigned. However, I found that AfterConstruction
is called BEFORE the component has been loaded from the stream. Thus, the
component's properties, including the event handler pointer, are not
assigned yet, and I cannot call the handler if any. Why so? Do I need to do
call OnCreate in Loaded method instead? The latter would not seem logical.
Thanks,
Ruslan
You have discovered the reason why TFrames don't have an OnCreate event,
there is simply no good place to fire it from. For a form the event can be
fired from Afterconstruction since it is the constructor of the form that
does the loading from the DFM resource. For a component that is dropped on
the form, however, the loading happens after the constructor has returned
(the component is created by the streaming system), or it does not happen at
all (when the component is dropped on the form in the designer). Call your
event "AfterLoaded" and fire it from an overriden Loaded method, get used to
the fact that the event may fire more than once (unless you code to guard
against that) since Loaded may be called more than once if the component is
used on a form with visual form inheritance. And it will not be called at all
in the designer when the component is dropped on the form the first time.
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Best regards,
Ruslan
Call this proc from the overrided Loaded:
procedure Txyz.DoAfterLoaded;
const FirstTime: boolean = true;
begin
if not FirstTime then exit;
FirstTime:=false;
if assigned(fOnAfterLoaded) then
fOnAfterLoaded(self);
end;
WL
No! If "FirstTime" is "static" variable (to say it in C-slang) the event
what only be called once for the whole program even if there were serveral
of the components.
You could Make FirstTime an instance variable. But then the event would be
called after the first load not after the last!?
A workaround could be to:
- Make FirstTime an instance variable.
- Call the event in the Paint-Method.
The Paint-Method would be surely late enough for this.
Another (better) workaround:
- Make FirstTime an instance variable.
-In the constructor send a message to your component or a invisible window
created with AllocateHWnd.
-When the message arives the loading is done. (Did not test, but im 99%
sure).
If you succeed (or not) please let us now.
Lothar Böhler
rb
Changing a const is possible. It is rather static but constant.
And Lothar is right that this will only fire for the first Loaded
occurance. I don't know if classes share their local const vars
but probably Lothar is right here as well.
WL
TAB.
rb
"Werner Lehmann" <w...@bwl.uni-kiel.de> wrote in message
news:3A0C95F6...@bwl.uni-kiel.de...
> Another (better) workaround:
> - Make FirstTime an instance variable.
> -In the constructor send a message to your component or a invisible window
> created with AllocateHWnd.
> -When the message arives the loading is done. (Did not test, but im 99%
> sure).
>
> If you succeed (or not) please let us now.
I believe this would work just fine, but my component does not have a
window.
Regards, and thanks for help!
Ruslan