A quick way to remove properties from .dfm files in Delphi
Asked Answered
R

4

10

I have recently modified one of my components, and it so happens it is no longer using one of the properties it used before.

However, those properties are written in multiple .dfm files throughout the project. Now, when i try to compile the project, i get "Error reading .: Property <...> does not exist"

The complicated part is that the property value is binary data (stored in multiple lines), and i cant just delete it with Delphi replace or notepad++ regexp (since they are single-line based).

So my question would be:

Are there any third party tools or ways to easily remove properties from multiple .dfm files?

Raptorial answered 2/3, 2012 at 7:47 Comment(4)
if you open your dfm and save it again, invalid property is not removed? looks strange..Umbles
@Umbles The problem is opening the .dfm file in the first place. The streaming code will object at the .dfm file read point.Ginger
@DavidHeffernan I thought IDE asks to 'ignore' or 'remove' incorrect property with binary fields. For ex: I place TAdvGlowButton (from TMS) to the form, then I replace field definition in form class (button1 : TButton), after I open form as text (alt+f12), and replace TAdvGlowButton to TButton (of course TMS button has more properties than standart). So, now DFM has invalid properties. if I try to open form, IDE asks "Ignore the error and continue?", and if I press Ok, then invalid properties are deleted.Umbles
@Umbles Maybe I'm remembering from the old days. I always just make my component able to deal with it all silently.Ginger
H
9

Try this tool Delphi DFM properties remover, works with old versions of delphi but maybe can help you.

Hollishollister answered 2/3, 2012 at 8:23 Comment(1)
Thank you this worked like a charm, does exactly what it should. Not sure why i wasnt able to google itRaptorial
G
4

One possible approach is to modify your component so that it is capable of simply ignoring these properties. That way you don't have to hunt them down in each and every .dfm file.

For example:

type
  TIgnoreFormPropertyHelper = class
  public
    class procedure IgnoreBooleanProperty(Reader: TReader);
    class procedure IgnoreIntegerProperty(Reader: TReader);
  end;

{ TIgnoreFormPropertyHelper }

class procedure TIgnoreFormPropertyHelper.IgnoreBooleanProperty(Reader: TReader);
begin
  Reader.ReadBoolean;
end;

class procedure TIgnoreFormPropertyHelper.IgnoreIntegerProperty(Reader: TReader);
begin
  Reader.ReadInteger;
end;

type
  TMyComponent = class(...)
  ....  
  protected
    procedure DefineProperties(Filer: TFiler); override;
  ....  

procedure TMyComponent.DefineProperties(Filer: TFiler);
begin
  inherited;
  Filer.DefineProperty('MyLegacyBooleanProperty',
    TIgnoreFormPropertyHelper.IgnoreBooleanProperty, nil, False);
  Filer.DefineProperty('MyLegacyIntegerProperty',
    TIgnoreFormPropertyHelper.IgnoreIntegerProperty, nil, False);
end;
Ginger answered 2/3, 2012 at 9:12 Comment(0)
C
1

The Jedi VCL contains a tool called DFMCleaner:

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 (f ex if the form is used by a property editor), Delphi generates an AV instead.

It is located in jvcl-install\devtools\DFMCleaner (project with source code and example configuration file)

Crimpy answered 4/3, 2012 at 18:15 Comment(0)
U
0

In my case simply closing the project and deleting the DProj file helped.

Unboned answered 9/6, 2015 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.