[fpc-pascal] csLoading and Create

Michael Van Canneyt michael at freepascal.org
Wed Jan 14 15:30:11 CET 2009



On Wed, 14 Jan 2009, Martin Friebe wrote:

> Hi,
> 
> If a component is loaded from a stream, then csLoading is set in
> ComponentState (or so I thought I understood the concept)
> So in my component i do  "if not(csLoading in componentState)" ...
> 
> However I found this does not work in the constructor Create. csLoading  is
> only set *after* the Constructor has been called.
> (This is unless it is an inline component?).
> - TReader does create the object with class.NewInstance (so create is not yet
> called)
> - the for inlined components it does set csInline, scLoading => for others it
> does not set anything
> - then the constructor create is called (but csLoading is not set)
> - only then does csLoading get set
> 
> Is this supposed to be like this? How else can I inside Create check if the
> component is loaded from a stream?

It is supposed to be like this. You cannot check this, and you shoud not.
A component should always behave the same, no matter whether it is being
streamed or not: You cannot a priori know whether a component of a certain
class will be streamed or not.

Michael.



More information about the fpc-pascal mailing list