Forum > Graphics

Icon from Lazarus icons resource

(1/1)

Dibo:
Hi,
Lazarus have very nice collection of icons (I guess "Tango icons"?). Some icons are included in project exe file (like bitbuttons glyps). Can I somehow use this icons at runtime? I can't find any resource using resource explorer (PE Explorer, Reshack). Example, I want use some icons from bitbutton in my graphic control or speedbutton. I found LoadFromLazarusResource function in TBitmap but I don't know ResName values of this icons. I just don't want clutter resources by adding this same icons.
Regards

Paul Ishenin:
Look for names at lcl\btn_icons.lrs, lcl\dialog_icons.lrs.

Icon sources are places in lcl\images

Dibo:
Thanks for reply!
I have some technical dillema. This is the code:

--- Code: ---SpeedButton1.Glyph := LoadBitmapFromLazarusResource(BitBtnResNames[bkOK]);
--- End code ---
Must I free SpeedButton1.Glyph before LoadBitmapFromLazarusResource? Because this function create new bitmap instance (Result := TBitmap.Create), but when I do this:

--- Code: ---SpeedButton1.Glyph.Free;
SpeedButton1.Glyph := LoadBitmapFromLazarusResource(BitBtnResNames[bkOK]);   

--- End code ---
... I have access violation. What about memory leaks?

Paul Ishenin:
SpeedButton.Glyph is a property. This property has setter method. In that setter method Assign() call is used to replace old bitmap content with new. Thus you cannot destroy SpeedButton.Glyph. You need to use temporary variable:


--- Code: ---B := LoadBitmapFromLazarusResource(BitBtnResNames[bkOK]);
SpeedButton1.Glyph := B;
B.Free;

--- End code ---

Or better use next call:

--- Code: ---SpeedButton11.LoadGlyphFromLazarusResource(BitBtnResNames[bkOK]);

--- End code ---

Navigation

[0] Message Index

Go to full version