'How to change a .dfm property with compiler directives?
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!
Solution 1:[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.
Solution 2:[2]
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;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brian |
| Solution 2 | Marco Luciano |
