Jump to content
Eric Grange

TToolButton.ImageName Delphi 11 vs Delphi 10

Recommended Posts

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
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

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
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 by Eric Grange

Share this post


Link to post

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
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
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
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

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 by Uwe Raabe

Share this post


Link to post

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

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 by Uwe Raabe

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×