The below question discusses how inheritance chain between TButton and TBitBtn has changed, namely the introduction of a common ancestor, TCustomButton.
What happened to TBitBtn and TButton inheritance chain?
In the past, those who wanted graphics on their button would opt for a TBitBtn, as it offered usage of bitmap glyphs.
In more recent versions of Delphi, the standard TButton allows to specify a TImageList, for png / jpg support, while TBitBtn does not.
My (long-time) button subclass inherits from TBitBtn, and changing that would mean a potential application-wide button redesign. No time for that. I want the ability to migrate things over time, in baby steps, without deleting and re-creating buttons (chance to miss the migration of a property or an event). Optimally, pick a button, wipe its glyph, put a png in its imagelist, over.
Looking at the sources of VCL.Buttons and VCL.StdCtrls, the bulk of the work for ImageList, ImageIndex ... is done at the common ancestor, TCustomButton. TButton only publishes those properties to be used at design-time.
Great, I can simply make my TBitBtn subclass publish those same properties. The properties are now visible in the object inspector. I can select an imagelist component, even pick an image index from the available images.
And this is where things stop working: the selected image doesn't get displayed at design-time, nor at runtime. Assign a glyph, it gets displayed without any problems. I tried looking at other properties which may interfere in the painting of the png (maybe some kind of transparency option), in vain.
EDIT:
This link mentions that TBitBtn purposely disables the usage of ImageList in favor of its own drawing:
http://codeverge.com/embarcadero.delphi.graphics/tbitbtn-with-png-on-d2009/1077124
Nonetheless, any suggestions on how I can achieve my "baby steps" migration described above from bmp icons to png ones, as smoothly as possible?
Version info: 10.3.1
Thanks!
I tested with Delphi 10.4.1 and it works perfectly.
At first, I tought about an interposer class ot make ImageIndex and Images published. This is not even required. TBitBtn in Delphi 10.4.1 has both properties already published. I had not noticed that before !
Here is the code:
unit BitBtnInheritenceDemoMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons,
System.ImageList, Vcl.ImgList;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
ImageList1: TImageList;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
// Properties could also be assigned thru object inspector
BitBtn1.Images := ImageList1;
BitBtn1.ImageIndex := 1;
end;
end.