[SOLVED] Component question lazarus / 31-LCL ---------------------------------------------------------------------- pcurtis · 2021-10-16 05:53 Consider this. I have a form and I place a component (derived from TComponent) on that form. The component has a boolean property HideOnShow. How do I make the component hide the main form on app startup? Where and how do I implement this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit MyTest; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, LResources, LCLIntf, Forms, Controls, Graphics, Dialogs, ExtCtrls,  StdCtrls, ComCtrls; type   { TMyTest}   TMyTest = class(TComponent)  private    fHideOnStart : Boolean;        function GetHideOnStart : Boolean;        procedure SetHideOnStart(aValue : Boolean);  protected      public    constructor Create(AOwner : TComponent); override;    destructor Destroy; override;  published    property HideOnStart : Boolean read GetHideOnStart write SetHideOnStart;  end; procedure Register; implementation constructor TMyTest.Create(AOwner : TComponent);begin  inherited Create(AOwner);end; destructor TMyTest.Destroy;begin  inherited;end; function TMyTest.GetHideOnStart : Boolean;begin  Result := fHideOnStart;end; procedure TMyTest.SetHideOnStart(aValue : Boolean);begin  if aValue <> fHideOnStart then    begin          fHideOnStart := aValue;        end;end; procedure Register; begin  RegisterComponents('Misc',[TMyTest]);end; end. ---------------------------------------------------------------------- pcurtis · 2021-10-16 08:10 I tried this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor TMyTest.Create(AOwner : TComponent);begin  inherited Create(AOwner);  if not (csDesigning in ComponentState) then    begin      fTimer := TTimer.Create(Self);      fTimer.Interval := 1;      fTimer.OnTimer := @OnTimer;    end;end;   procedure TMyTest.OnTimer(Sender : TObject);begin  if (Self.Owner as TForm).Showing then    begin      (Self.Owner as TForm).Hide;      fTimer.Enabled := False;    end;end; but the main form still appears for a short time. ---------------------------------------------------------------------- balazsszekely · 2021-10-16 08:29 Hi pcurtis, Try the same thing with Application.Mainform: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMyTest.OnTimer(Sender : TObject);begin  if Application.Mainform  <> nil then  begin    //...  end;end; ---------------------------------------------------------------------- pcurtis · 2021-10-16 08:44 The form still appears briefly ---------------------------------------------------------------------- howardpc · 2021-10-16 10:37 Quote from: pcurtis on October 16, 2021, 07:53:10 amHow do I make the component hide the main form on app startup? App startup happens before your component exists. You can only hide the main form at startup using Application.ShowMainForm := False in your .lpr ---------------------------------------------------------------------- balazsszekely · 2021-10-16 11:00 @howardpc QuoteApp startup happens before your component exists.That's not true. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  Application.CreateForm(TForm1, Form1); //components are created here Application.Run; //app. start   The attached package will hide the main form, but a timer is needed because the component must wait until Application.Mainform is assigned. Another possible solution is  to override TApplication's Notification method: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Notification(AComponent: TComponent; Operation: TOperation); override; In this case a timer is not needed, because we can catch the creation of mainform. ---------------------------------------------------------------------- howardpc · 2021-10-16 11:56 Thanks for the correction. Apologies for spreading disinformation. ---------------------------------------------------------------------- pcurtis · 2021-10-16 12:11 OK. Thanks it works.