RAD Studio
ContentsIndex
PreviousUpNext
Initializing After Loading

After a component reads all its property values from its stored description, it calls a virtual method named Loaded, which performs any required initializations. The call to Loaded occurs before the form and its controls are shown, so you do not need to worry about initialization causing flicker on the screen. 

To initialize a component after it loads its property values, override the Loaded method.

Note: The first thing to do in any Loaded method is call the inherited Loaded method. This ensures that any inherited properties are correctly initialized before you initialize your own component.
The following code comes from the TDatabase component. After loading, the database tries to reestablish any connections that were open at the time it was stored, and specifies how to handle any exceptions that occur while connecting.

procedure TDatabase.Loaded;    
begin
  inherited Loaded;                                     { call the inherited method first}
  try
    if FStreamedConnected then Open                            { reestablish connections }
    else CheckSessionName(False);
  except
    if csDesigning in ComponentState then                            { at design time... }
      Application.HandleException(Self)                { let Delphi handle the exception }
    else raise;                                                     { otherwise, reraise }
  end;
end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!