Recent

Author Topic: TComponent.Loaded doesn't executed when the comp. dropped to the form [ANSWERED]  (Read 1329 times)

totya

  • Hero Member
  • *****
  • Posts: 577
Hi!

This is a very simple demo component:

Code: Pascal  [Select]
  1. unit TestComponent;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Dialogs, StdCtrls;
  9.  
  10. type
  11.   TTestComponent = class(TCustomListBox)
  12.   protected
  13.     procedure Loaded; override;
  14.   end;
  15.  
  16. procedure Register;
  17.  
  18. implementation
  19.  
  20. procedure TTestComponent.Loaded;
  21. begin
  22.   Inherited Loaded;
  23.  
  24.   Items.Text:= 'TEST OKAY'; Invalidate;
  25. end;
  26.  
  27. procedure Register;
  28. begin
  29.   RegisterComponents('My Stuff',[TTestComponent]);
  30. end;
  31.  
  32. end.

Well, If I drop this component to the form, the Loaded won't start as I see. This is normal?
If I running the project, Loaded is works. I know, I can use CreateWnd, but the question is the Loaded, because I see FileCtrl/TFileListBox component source, so this component override only the Loaded method, and files appear after TFileListBox component droped to the form, so I think Loaded is works... but how?

Thanks!
« Last Edit: June 18, 2018, 07:27:27 am by totya »

jamie

  • Hero Member
  • *****
  • Posts: 2168
Loaded is called when your program loads the properties from the resource of your EXE.

basically when all the properies get streamed from the file the LOADED method gets called to allow you
to do some additional settings, it also sets the csLoaded to true.

The IDE does not do this, it creates the control and sets only what is needed for the IDE and does not
read the values from the stream.

Number 1 at blue screen app creations!

totya

  • Hero Member
  • *****
  • Posts: 577
Thanks for the answer! Otherwise when IDE started with a project, the project components loaded methods are called.