2

Is it possible to make a compiler directive for the .dfm properties introduced on Delphi 11 like

  {$IFDEF CompilerVersion > 34.0}
  PixelsPerInch = 96
  {$ENDIF}

So other developers that use 10.4.2 or lower are able to use the same unit without having to ignore the error and/or then commiting the form without that attribute?

Tried doing it that exact way listed above but it doesn't compile, it throws a Linker error on the line of the conditional.

Thanks in advance!

Mobius one
  • 171
  • 3
  • 12
  • 2
    IFDEF won't work because the compiler doesn't look into the DFM at all. – Uwe Raabe Nov 22 '21 at 23:33
  • I regularly open my projects in both Delphi 11 and earlier versions, esp. my Android projects, and I just "live with" such properties being deleted and re-added. The IDE also demands that units that haven't changed in any way, be saved. I live with this too. – Freddie Bell Nov 23 '21 at 08:05
  • If you really need your project to support multiple versions, consider having the TForm override the virtual `DefineProperties()` to provide dummy properties for older versions, and then you can IFDEF that code as needed. – Remy Lebeau Nov 23 '21 at 17:51
  • Looking at documentation the problem seems to be that in Delphi 11 property `PixelsPerInch` is now declared as `Public` and no longer as `Published`. I'm guessing you could solve this by manually changing the `PixelsPerInch` property visibility of ypur form to become `Published` by creating `Published` section in your form definition and then adding `property PixelsPerInch` in it. This should make sure that the said property can be populated from DFM at runtime. But I'm not sure if this will have any effect on Delphi 11 at design time. So it might still remove the said property from DFM – SilverWarior Nov 23 '21 at 22:36
  • It might also be good to raise this issue on Embarcadero Quality Center as it is possible that change of `PixelsPerInch` property from `Published` to `Public` visibility was not intentional. – SilverWarior Nov 23 '21 at 22:39
  • @RemyLebeau could you reply with an example on how that would be done please? I noticed that only DataModules are having this PPI issue. – Mobius one Nov 25 '21 at 21:13
  • @SilverWarior changing a property visibility from Public to Published if that would do the trick then it'd be perfect solution, but how can I validate that? – Mobius one Nov 25 '21 at 21:13
  • @Mobiusone Make a change and see if the Error you get in Delphi 11 during runtime still persists. I don't have Delphi 11 installed so I can't test this myself. – SilverWarior Nov 26 '21 at 16:30

2 Answers2

1

One option is to use DFMCleaner which is included in JVCL: JEDI Visual Component Library.

DFMCleaner is a tool to remove unsupported properties from DFMs. If you save a dfm file in one version of Delphi and want to use it in an earlier version, chances are there are some unsupported properties in it, generating an error when the form is opened in Delphi. What's even worse, if the dfm is part of a design-time package, Delphi will install the package without errors but when you try to access the form at design-time (for example if the form is used by a property editor), Delphi generates an AV instead.

After JVCL is unzipped it is in \jvcl\devtools\DFMCleaner

There are other such utilities available as well. You can $IFDEF around code in the OnCreate to make sure the property is set how you want it in newer Delphi versions if you are worried it will get lost.

Brian
  • 6,717
  • 2
  • 23
  • 31
0
TDataModule.PixelsPerInch implementation: 
First...`enter code here`

Search Find in files.... => "= class(TDataModule)"


After... implement each DataModule .pas

  private
    { Private declarations }
    FPixelsPerInch: Integer;
    //
    ...
    //
    procedure ReadPixelsPerInch(Reader: TReader);
    procedure WritePixelsPerInch(Writer: TWriter);
    //
    ....



  protected
    procedure DefineProperties(Filer: TFiler); override;
  .... 



  public
    { Public declarations }
    property PixelsPerInch: Integer read FPixelsPerInch write FPixelsPerInch;
    //
    ...







procedure TDm?????.DefineProperties(Filer: TFiler);
var
  Ancestor: TDataModule;
begin
  inherited;
  Ancestor := TDataModule(Filer.Ancestor);
  Filer.DefineProperty('PixelsPerInch', ReadPixelsPerInch, WritePixelsPerInch, True);
end;

procedure TDm?????.ReadPixelsPerInch(Reader: TReader);
begin
  FPixelsPerInch := Reader.ReadInteger;
end;

procedure TDm?????.WritePixelsPerInch(Writer: TWriter);
begin
  Writer.WriteInteger(FPixelsPerInch);
end;