[SOLVED] Form location lazarus / 21-General ---------------------------------------------------------------------- pcurtis · 2022-02-28 15:13 I have a non-visual component based on TComponent. How can I get the parent forms current position during runtime? ---------------------------------------------------------------------- Zvoni · 2022-02-28 15:21 Quote from: pcurtis on February 28, 2022, 04:13:54 pmI have a non- visual component based on TComponent. How can I get the parent forms current position during runtime? A TForm is a distant descendant of TComponent https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tform.html The Owner-Property of your component? Provided you inserted your component https://www.freepascal.org/docs-html/rtl/classes/tcomponent.owner.html https://www.freepascal.org/docs- html/rtl/classes/tcomponent.insertcomponent.html 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 WriteLn(TForm(MyComponent.Owner).Top); ---------------------------------------------------------------------- howardpc · 2022-02-28 15:36 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 uMain; {$mode objfpc}{$H+} interface uses  Classes, Forms, LazLogger; type   TNonVisual = class(TComponent)  private    FOwningForm: TForm;  public    constructor Create(AOwner: TComponent); override;    function GetParentFormPosition: TPoint;  end;   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);  private    nv: TNonVisual;  end; var  Form1: TForm1; implementation {$R *.lfm} procedure TForm1.FormCreate(Sender: TObject);var  pt: TPoint;begin  nv := TNonVisual.Create(Self);  pt := nv.GetParentFormPosition;  DebugLn(['non-visual''s owning form position is X:',pt.X,', Y:',pt.Y]);end; procedure TForm1.FormDestroy(Sender: TObject);begin  nv.Free;end; constructor TNonVisual.Create(AOwner: TComponent);begin  Assert(AOwner.InheritsFrom(TForm),'TNonVisual needs a form as owner');  inherited Create(AOwner);  FOwningForm := AOwner as TForm;end; function TNonVisual.GetParentFormPosition: TPoint;begin  Result := FOwningForm.ClientToScreen(FOwningForm.BoundsRect.TopLeft);end; end. ---------------------------------------------------------------------- wp · 2022-02-28 16:13 The following code is a bit more general because it is possible that a component is not owned by a form at all: 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 function TForm1.GetOwningForm(AComponent: TComponent): TCustomForm;begin  while (AComponent <> nil) and not (AComponent is TControl) do    AComponent := AComponent.Owner;  if AComponent <> nil then    Result := GetParentForm(TControl(AComponent))  else    Result := nil;end;  procedure TForm1.Button2Click(Sender: TObject);var  F: TForm;begin  F := GetOwningForm(FTestComponent) as TForm;  if F <> nil then    ShowMessage(F.Left.ToString)  else    ShowMessage('Not owned by a form');end; ---------------------------------------------------------------------- pcurtis · 2022-02-28 16:22 Thanks all.