So… I’m working on a little custom FireMonkey control. As in the VCL, if you want to handle drawing a custom control yourself, you need to override its Paint method. In my case the override was looking like this:
procedure TMyChildControl.Paint;
begin
if (Parent <> nil) and (Parent.Parent is TMyOtherControl) then
Canvas.Font.Assign(TMyOtherControl(Parent.Parent).Font);
Canvas.FillText(LocalRect, SomeText, False, 1, [], TTextAlign.taCenter);
end;
If you’re wondering, this was partly a workaround for the fact FMX doesn’t have a ‘parent font’ concept like the VCL. Anyhow, the code seemed to work fine until I enabled drag and drop. In FireMonkey, the drag image for an internal drag and drop operation is dynamically created from the image of the dragged control (good), but in my case, the drag image wasn’t being drawn with the proper font set. Digging through the source I discovered the reason: BeginAutoDrag calls MakeScreenshot to generate the drag image, which calls PaintTo… whose final parameter is a parent property override that defaults to nil. As such, while my Paint override was being called, the Parent property was returning nil inside of it. Argh…