I might not understand your concern.
1/2 Even when a form has a parent form assigned, shouldn't mouse movements over child's form top-left corner return the (0,0) coordinates!? Same as moving the mouse over the top-left corner of the button in the above example, it returns (0,0). Moving the mouse over the button would not trigger the OnMouseMove event of it's parent form, no matter if the button has an OnMouseMove event assigned or not. Shouldn't be the same when moving the mouse over a child form!?
The only concern I've had was related to using TFrames, but those are unusable even in linux-gtk2(using latest development sources). Notice that custom-drawn lacks dialogs implementation(like Open/Save file dialog), so it might take years before implementing TFrames in custom-drawn. When implemented, most likely
FindControlPositionRelativeToTheForm will need an additional "
if (ALCLControl is TCustomFrame) then ..." line inserted before the proposed "
if (ALCLControl is TCustomForm) then Exit(Point(0,0));".
2/2 A different idea is to change the function to
function FindControlPositionRelativeToTheForm(ALCLControl: TWinControl; AConsiderScrolling: Boolean = False): TPoint;
var
lParentControl: TWinControl;
lParentHandle: TCDBaseControl;
lScroll, lParentPos: TPoint;
begin
lParentControl := ALCLControl.Parent;
//Return (0,0) if the parent control is nil
if lParentControl = nil then Exit(Point(0, 0));
// Iterate to find the appropriate BaseWindowOrg relative to the parent control
Result := Point(ALCLControl.Left, ALCLControl.Top);
repeat
if AConsiderScrolling and lParentControl.HandleAllocated then
begin
lParentHandle := TCDBaseControl(lParentControl.Handle);
lScroll := Point(lParentHandle.ScrollX, lParentHandle.ScrollY);
end
else lScroll := Point(0, 0);
if (lParentControl is TCustomForm) then lParentPos := Point(0, 0)
else lParentPos := Point(lParentControl.Left, lParentControl.Top);
Result.X := Result.X + lParentPos.X - lScroll.X;
Result.Y := Result.Y + lParentPos.Y - lScroll.Y;
lParentControl := lParentControl.Parent;
until lParentControl = nil;
end;
The above code returns (0,0) when the LCL control has no parent. This solution works for me, too.