6

I have an application written in Delphi 6 and compiled on Windows XP. Usually I leave 8px free between controls and the edges of forms.

When this app runs on Vista or Win 7 this gap is smaller or not present at all. I think this might be because these versions of Windows have thicker form borders.

Now I am moving the app to Delphi 2007. In the form designer the forms have lost the bottom and right gaps.

How should I deal with this? I have hundreds of forms and don't want to go changing them all. Also, most of our users run the app on Win XP so I don't want to make it look bad in XP.

cja
  • 9,512
  • 21
  • 75
  • 129
  • 2
    there's something else you aren't telling us. I've recently ported from d6 to d2010 and had no such trouble – David Heffernan Jun 02 '11 at 11:43
  • Are you or have you tried using a Manifest? Maybe you could specify XP Compatibility mode? – Tom Jun 02 '11 at 11:57
  • @DavidHeffernan "something wicked this way comes". Just hit the wall, that TForm.ClientWidth returns a totally crazy result on Win8.x regardless of DPI .... – Arioch 'The Mar 28 '17 at 09:56

1 Answers1

11

Short version: change all form's to AutoScroll = False


The problem is the form's AutoScroll property, and how it affects which form size is stored in the DFM.

If AutoScroll is true (the default) the DFM will store Width and Height:

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 544
  Height = 375
  Caption = 'Form1'
  ...

If AutoScroll is false (the preferred setting) the DFM will store ClientWidth and ClientHeight:

object frmSplash: TfrmSplash
  Left = 192
  Top = 114
  ClientWidth = 536
  ClientHeight = 348
  Caption = 'Form1'

The problem with storing Height is what happens when the user's caption bar is a different size than your development machine, e.g.

  • you develop on Windows 2000, program runs on Windows XP
  • you develop on Windows XP, program runs on Windows Vista
  • you develop with small fonts, program runs with large fonts

Windows 2000 had a 4 pixel border, with a 23 pixel caption bar. With the DFM storing a Height of 375, this leaves 348px for form client area.

Run the same program on Windows XP, which has a taller (28 pixel) caption bar. With the DFM storing a Height of 375 pixels, this leaves 343px for client area.

Your form "got 5 pixels shorter".

You need to force Delphi to store the ClientWidth and ClientHeight in the DFM by turning AutoScroll off.

Now when you create your 348px tall form on Windows XP, it will continue to have 348 pixels in the client area - and be however extra tall is required to have a caption bar.

i go so far as to have an OutputDebugString and a breakpoint trigger if my helper library code finds any form that mistakenly has AutoScroll set to true.


Edit: Since i try to be a good developer, i make my form's respect the user's font preference. During the OnCreate of all my forms i call a StandardizeForm(Self) function that:

  • scales the form to match the user's default font size
  • changes the font on all controls on the form to the user's preference
  • issues an ODS if the form is set mistakenly set to Scaled
  • issues an ODS and breakpoint if AutoScroll true (and sets it to false)
  • issues an ODS and breakpoint if ShowHint is false (and turns it on)
  • etc

You can do something similar. Yes you'd have to add:

procedure TCustomerEditForm.FormCreat(Sender: TObject);
begin
   StandardizeForm(Self); //Pay your taxes!
   ...
end;

But it's worth it for me.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • Also, why don't you have your own tax-free form class? – cja Jun 08 '11 at 11:22
  • 1
    @cja: There's little value gained by forcing everyone to install a new design-time package. This way is ***much*** easier. – Ian Boyd Jun 16 '11 at 03:15
  • @IanBoyd You can make a class available to your project without installing a new design time package – cja Oct 16 '13 at 13:44
  • there is an opensourced project, that i did not find time to review though. Maybe ut would make sense for you to review it and perhaps join efforts. See https://github.com/delphinotes/BaseForms.git – Arioch 'The Mar 28 '17 at 09:53