Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-09

When is TComponent.Loaded called?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

As the subject says. When is TComponent.Loaded called? I'm trying to use it in fpGUI to initialize a few things in a component, but Loaded never seems to execute.

Reading the Kylix 3 help, it says Loaded is called by the streaming system that loads the 'form files'. Well fpGUI doesn't use 'form files' (like *.dfm or *.lfm). Instead the GUI Designer creates the components via code in a normal *.pas unit, which is called after the Form's constructor has completed.

I gather it is safe to assume the FCL never calls a TComponent's Loaded method anywhere?

fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/
Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 14 lines
Hi, As the subject says. When is TComponent.Loaded called? I'm trying to use it in fpGUI to initialize a few things in a component, but Loaded never seems to execute. Reading the Kylix 3 help, it says Loaded is called by the streaming system that loads the 'form files'. Well fpGUI doesn't use 'form files' (like *.dfm or *.lfm). Instead the GUI Designer creates the components via code in a normal *.pas unit, which is called after the Form's constructor has completed. I gather it is safe to assume the FCL never calls a TComponent's Loaded method anywhere?

It is called in the streaming code, classes.inc in TReader.ReadRootComponent

It's used to perform certain actions which should only be done after all properties are loaded.

You should never call loaded directly (in fact, you can't since it is protected).

The reason for it's presence is simple: you can't force the order of loading properties. Suppose you have a dataset component: the active property is one of the first to be set: none of the properties which actually matter (SQL, Database etc) are set, so putting active to True would raise an error. Therefore the action of setting 'Active' is deferred till the Loaded call: then the needed properties are normally all set.

When creating components in code, it's assumed that you set them in the proper order prior to setting Active.

Michael.