Bug Report T941528
Visible to All Users

TdxForm and TdxCustomForm descendants - A form embedded into a scaled form is scaled twice in an application built with RAD Studio 10.4 Sydney

created 4 years ago

If a TdxForm descendant is embedded into another form, it is scaled twice with DPI<>96.

I had to start descending from TdxForm for the embedded forms because otherwise an ExpressBars Toolbar would not be scaled.

Please run the attached sample project.

  1. When started on a monitor with 96dpi, pressing "Embed" results in this:
    Clipboard-File-1.png
  2. If I move that window to a montor with 175% (e.g. by pressing Win+Right), it is scaled correctly like this:
    Clipboard-File-2.png
  3. Now if I press embed again, so the existing embedded form is destroyed and recreated, it is scaled twice, resulting in this:
    Clipboard-File-3.png

I tried to debug this and by the time I end up in TdxFormHelper.ScaleForPPI (starting from TdxForm.SetParent), the call to TdxFormHelper.ScalingBegin will actually cause the handle of the form to be allocated because of the IsWindowVisible(AContainer.Handle). By that time, the form is already scaled for the first time and then is scaled another time.

I found the tickets T809409 and T552235 which sound similar, but since both have been fixed and my problem still occurs with 20.1.4, my scenario seems to be different.

Show previous comments (7)
SM SM
Sebastian Modersohn 4 years ago

    I'm not trying to argue here, just posting my observations. My understanding is that the check for IsScaleChanging prevents a second nested scale at the beginning of the first scale (because of the window being created). I don't see how this is preventing the otherwise necessary call to ScaleForPPI under normal circumstances.

    Also, using my attached sample project, step 3 shows the form exactly like step 2, so buttons and the form have indeed been scaled correctly. In my real-world project, the forms are much more complex, some with LayoutControl, some without - and they look fine after the fix.

    I'm sure you guys have a much deeper understanding of this rather complex issue and most importantly a wider range of test-cases. So here's hoping you can come up with a universal fix in the not too distant future.

    DevExpress Support Team 4 years ago

      Thanks, Sebastian! I hope we will be able to find a universal solution soon.

      SM SM
      Sebastian Modersohn 4 years ago

        In the meantime, I've discovered that even in Delphi 10.4, there's still a bunch of open bugs in the VCL regarding scaling (I'm sure that's old news to you).

        But this has led me to find a workaround, which doesn't require a fix from you and since there's only one place where I'm creating those embedded forms, I'm fine.

        RSP-31137 (evolved from RSP-19012) describes the workaround, which when applied to my demo looks like this:

        Delphi
        procedure TMainForm.btnEmbedClick(Sender: TObject); var subForm: TEmbedForm; begin while Panel1.ControlCount > 0 do Panel1.Controls[0].Free; subForm:= TEmbedForm.Create(Self); subForm.HandleNeeded; subForm.ScaleForPPI(CurrentPPI); subForm.Parent:= Panel1; subForm.Show; end;

        AFAIU this ensures a first scale before the Parent is actually set - which destroys the handle for unparented forms. The second scale caused by SetParent then does nothing (because CurrentPPI stays the same).

        Answers approved by DevExpress Support

        created 4 years ago

        We have addressed the issue described in this ticket and will include a fix in our next maintenance update. To apply this solution before official release, request a hotfix by clicking the appropriate version link.

        Note: Hotfixes may be unavailable for betas/updates set for release within a week.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.