Quantcast
Channel: User Peter - Stack Overflow
Viewing all articles
Browse latest Browse all 81

Override VCL class/component protected method - How to code and use?

$
0
0

I am rewriting old existing code and I'm giving the icons an overhaul. I used to have bitmaps assigned to TMenuItems but I'm changing that in favor of ImageIndex and a TImageList with colordepth 32bit, containing icons with an alpha channel. The ImageList is created and populated with icons at design time. The ImageIndex are assigned during program startup and changed if/when appropriate.

I noticed that when a MenuItem is disabled (enabled = false), the resulting image doesn't look great (at all) and I read that this is due to VCL. Mentioned link also links to Delphi code that can convert an icon to its greyscale values.

I'm not fluent in Delphi nor changing VCL components, subclassing them, inheriting from them etc. I normally simply use what is available without changing it. so I'm starting with some basic questions:

Here's a very simple attempt to inherit from TImage and override DoDraw(), to make it never disable the icon in the first place (decipering the Delphi code to greyscale can be done in a second step)

class MyTImageList : public TImageList    {    public:    __fastcall MyTImageList(Classes::TComponent* AOwner)        : TImageList(AOwner) {} ;    virtual __fastcall DoDraw(int Index, TCanvas *Canvas, int X, int Y, unsigned int Style, bool Enabled = true)        {        return TImageList::DoDraw(Index, Canvas, X, Y, Style) ;        }    };

FYI: I use C++ Builder 2009It does not compile, error: [BCC32 Error] Main.h(1018): E2113 Virtual function '_fastcall TMainForm::MyTImageList::DoDraw(int,TCanvas *,int,int,unsigned int,bool)' conflicts with base class 'TCustomImageList'

Since I'm very insecure about inheriting from VCL component classes I'm not sure if I'm dealing with a typo or something very constructively wrong ? Kindly enlighten me.

Assuming this compiles I'm actually not sure how to proceed further either.Because the ImageList is created at design time, and used throughout the code. For this change to work I have to work with 'MyTimageList'.

So, do I create MyTimageList during Form construction and Assign() the content of the design-time-ImageList, or is there a more efficient way to avoid copying over everything ?

Actually, thinking about the latter question more, I could simply use the internal ImageList of the design time Imagelist instance.


Viewing all articles
Browse latest Browse all 81

Latest Images

Trending Articles





Latest Images