Hello,
I have got a plugin system for one of my applications, using loadpackage. However, I am finding that when I add a button to the main menu from each plugin, the image I am loading - ImageList1.getbitmap(0, bsbarButton.Glyph) - is not appearing on the button. Screenshot attached - the four white buttons are all loaded by the plugin system.
The code I am using to create the button is below. Am I doing something wrong? If not, I can create an example application to show what is happening.
Thanks for your help?
Regards
Angus Miller
Delphiprocedure TOrderProcessPlugIn.SetMenu(BarManager: TdxBarManager);
var
AItemLink: TdxBarItemLink;
bsbarButton: TdxBarButton;
begin
BarManager.bars[1].lockupdate := True;
bsbarButton:= TdxBarButton.Create(BarManager);
bsBarButton.Caption := 'Process Orders';
bsbarButton.Enabled := True;
ImageList1.getbitmap(0, bsbarButton.Glyph);
AItemLink := BarManager.Bars[1].ItemLinks.Add;
AItemLink.Item := bsbarButton;
bsBarButton.visible := ivalways;
OrderProcess.btOrderProcess:= bsBarButton;
OrderProcess.btOrderProcess.OnClick:= OrderProcess.OrderProcessFormClick;
BarManager.bars[1].lockupdate := False;
end;
Steps to Reproduce:
Run the attached sample and click the TEST button.
Actual Results:
White squares.
Expected Results:
Correct glyphs.
Hi Angus,
The problem seems is caused by the nature of an ImageList. Basically, taking glyphs from an ImageList in such a manner isn't quite correct and may lead to different problems (like the described one). This is because an ImageList stores additional information, not only an image. In particular, the image's mask is stored. The GetBitmap method doesn't retrieve the mask and as a result, the image may be displayed wrong. For example, the elements matching the background color won't be displayed.
To solve the problem in our test sample, you should use the following code:
type TBitmapAccess = class(TBitmap); <<<<< ADD procedure TForm1.BitBtn1Click(Sender: TObject); begin // WRONG dxBarButton2.Glyph.PixelFormat := pf24bit; <<<<< ADD dxBarButton2.Glyph.Canvas.Brush.Color := clFuchsia; <<<<< ADD dxBarButton2.Glyph.Canvas.FillRect(Rect(0, 0, 16, 16)); <<<<< ADD ImageList1.GetBitmap(0, dxBarButton2.Glyph); TBitmapAccess(dxBarButton2.Glyph).Changed(nil); <<<<< ADD // OK ImageList1.GetBitmap(0, BitBtn1.Glyph); end;
If this approach doesn't work in your project, please send us this sample. We will try to find a solution for your particular situation.
Thanks,
Serge