Eric Grange 11 Posted July 17, 2023 Hi, when saving a form containing a TToolButton or a TAction, Delphi 11 saves an ImageName property in the dfm, which did not exist in Delphi 10. However for my particular codebase, I would like to maintain DFM compatibility across Delphi versions, so I am looking at ways to prevent Delphi 11 from saving this property (which is unnecessary: removing it from the dfm manually doesn't break anything, and actually it only gets added to forms that were edited in Delphi 11, forms never edited in Delphi 11 compile and run fine in Delphi 11). One approach could be having TToolBar creating a subclass of TToolButton (either in D10 to add a dummy property, or in D11 to replace the stored), but TToolButton creations are hard-coded deep into multiple TToolBar methods (like the huge TToolBar.CNNotify), so this would require basically ripping apart TToolBar, and using simple detours would be impractical due to the many private methods. TToolButton.IsImageStored would be simple to detour, except I would need to do it in the IDE, which would break the use cases where it's not unnecessary. Any other ideas or is this a dead horse ? 😕 Share this post Link to post
David Heffernan 2345 Posted July 17, 2023 21 minutes ago, Eric Grange said: Any other ideas or is this a dead horse ? Simple. Develop in the lowest version that you wish to support. Share this post Link to post
A.M. Hoornweg 144 Posted July 17, 2023 Or write a tiny command line program that scans a dfm file and removes that property. Run that program prior to committing code to your source code repository. TortoiseSVN allows you to fully automate this by setting "hooks", I don't know about Git. Share this post Link to post
David Heffernan 2345 Posted July 17, 2023 (edited) There's also this technique Edited July 17, 2023 by David Heffernan Share this post Link to post
Eric Grange 11 Posted July 17, 2023 (edited) Quote Simple. Develop in the lowest version that you wish to support. Hehe 🙂 might be simpler to forego the IDE and use VSCode or Notepad++ in that scenario... IDE has a tendency to consider the dfm changed even when just opening a form's code and not changing anything. As to why I prefer editing in Delphi 11, well, simple code navigation (ctrl+click, etc.) stops working very quickly in Delphi 10 on larger projects. Quote Or write a tiny command line program that scans a dfm file and removes that property. Run that program prior to committing code to your source code repository. TortoiseSVN allows you to fully automate this by setting "hooks", I don't know about Git. Yes, probably the route I will be be taking, TortoiseGit has them too. Edited July 17, 2023 by Eric Grange Share this post Link to post
Uwe Raabe 2057 Posted July 17, 2023 The ImageName can only be stored when the linked image list supports it. A plain old TImageList does not, so that won't make any problems. The new TVirtualImageList introduces ImageName support, but makes it configurable with its ImageNameAvailable property. Setting that to False avoids setting the ImageName property on the linking controls. You might have to clear existing ImageName values manually, though. Share this post Link to post
Eric Grange 11 Posted July 17, 2023 1 hour ago, Uwe Raabe said: Setting that to False avoids setting the ImageName property on the linking controls. You might have to clear existing ImageName values manually, though. Thanks, that does it for ImageName, but now the issue becomes about ImageNameAvailable property, which did not exist in Delphi 10 🙂 The default attribute for ImageNameAvailable property is hard-coded to True, but this could be worked out by subclassing the image list, reintroducing the property, and then using the image list subclass everywhere... I will probably stick with the hook script for now. Share this post Link to post
Uwe Raabe 2057 Posted July 17, 2023 12 minutes ago, Eric Grange said: this could be worked out by subclassing the image list, reintroducing the property, and then using the image list subclass everywhere... You can as well override the IsImageNameAvailable function for that subclass and just return False. Share this post Link to post
Eric Grange 11 Posted July 17, 2023 Quote You can as well override the IsImageNameAvailable function for that subclass and just return False. Unfortunately there is no IsImageNameAvailable in TVirtualImageList, in the VCL it's declared like this property ImageNameAvailable: Boolean read FImageNameAvailable write FImageNameAvailable default True; Share this post Link to post
Uwe Raabe 2057 Posted July 17, 2023 (edited) In 10.4+ it is and versions before have no ImageName properties. function TVirtualImageList.IsImageNameAvailable: Boolean; begin Result := FImageNameAvailable; end; Actually that function is introduced in TCustomImageList. It is just overridden in TVirtualImageList. Edited July 17, 2023 by Uwe Raabe Share this post Link to post
Eric Grange 11 Posted July 17, 2023 The property and snippet is from Delphi 11.3, did they walk back on the method after 10.4 ? It's definitely not there in 10.3 indeed. Share this post Link to post
Uwe Raabe 2057 Posted July 17, 2023 (edited) In 10.3 there is just no ImageName property in TToolButton either. ImageName support started with 10.4. In 11.3 there still is function TVirtualImageList.IsImageNameAvailable: Boolean; Edited July 17, 2023 by Uwe Raabe Share this post Link to post
Eric Grange 11 Posted July 17, 2023 Oh, yes, sorry, I had not noticed it. Share this post Link to post