* * *

Author Topic: TBCImageButton: embed image file in exe  (Read 1269 times)

Nimral

  • Jr. Member
  • **
  • Posts: 78
TBCImageButton: embed image file in exe
« on: February 14, 2017, 04:04:07 pm »
Hi all,

I just made my first steps with the BGRAControls library. Right now I load the images from external .png files, which works well, and is allright for development.

To ease installation, in the final product, I'd like to embed those files into my program file as resources.

Can this be done?

Thnx,

Armin.
Using Lazarus 1.6.2 on Windows 10/7/XP, VMWare Workstation 12

lainz

  • Hero Member
  • *****
  • Posts: 1978
  • Nace una flor, todos los días sale el sol...
    • BGRABitmap
Re: TBCImageButton: embed image file in exe
« Reply #1 on: February 14, 2017, 04:22:33 pm »
Yes you can. See attached project.

You need to go to Project Options > Resources and add all the bitmaps, in this case the bitmap is sample_1.png.

First add LCLType. Then for each image OnCreate do this:

Code: Pascal  [Select]
  1. implementation
  2. uses
  3.   LCLType;
  4.  
  5. {$R *.lfm}
  6.  
  7. { TForm1 }
  8.  
  9. procedure TForm1.FormCreate(Sender: TObject);
  10. begin
  11.   BCImageButton1.LoadFromBitmapResource('SAMPLE_1', RT_RCDATA);
  12. end;    

To compile this in other system than Windows you need to download and install "windres": http://wiki.freepascal.org/Lazarus_Resources#Checking_you_have_windres

If the image is a .BMP you need to use RT_RCDATA too (change that in the resource), RT_BITMAP doesn't works.

Maybe I will change that method so you need to pass only 'SAMPLE_1'. I will add it in master of bgracontrols on GitHub: Done, please download the master and use like this:

Code: Pascal  [Select]
  1. BCImageButton1.LoadFromBitmapResource('SAMPLE_1');
« Last Edit: February 14, 2017, 04:32:13 pm by lainz »

Nimral

  • Jr. Member
  • **
  • Posts: 78
Re: TBCImageButton: embed image file in exe
« Reply #2 on: February 14, 2017, 04:55:08 pm »
Hi Lainz,

thanks for your suggestion, I'll check this out this evening.

Quick question: BGRAControls has a quite comprehensive set of controls, but there are some standard controls missing, like TEdit or TComboBox.

Furthermore I had not much success using the Skin Manager, it seems to affect only a few controls (buttons mostly) yet, but not all the others.

To me, BGRAControls seems not yet finished? Is this correct, and if yes, any chance you sink some more time into finishing it, so it's becoming a full replacement of the standard controls palette?

Armin

Using Lazarus 1.6.2 on Windows 10/7/XP, VMWare Workstation 12

lainz

  • Hero Member
  • *****
  • Posts: 1978
  • Nace una flor, todos los días sale el sol...
    • BGRABitmap
Re: TBCImageButton: embed image file in exe
« Reply #3 on: February 14, 2017, 05:15:33 pm »
Hi,

There are missing components and you're right, the skin manager is theming only buttons.

There's a TEdit under the tab BGRA Custom Drawn, but has only the dark theme. The last addition was a themed ListBox.

I'm currently switching from Lazarus to Electron (http://electron.atom.io/). And in there I have any component I want with any theme I can imagine. If I need FPC I can build a command line exe and work with it with the Electron app.

If anyone is interested on working on BGRAControls contact me.

Edit: some misunderstanding, i'm not leaving but using FPC in combination with Electron if an app requires it. But I currently don't need lazarus for UI, since I have an alternative. And I can't make all these kind of controls alone!

If you need a better library you can use for example fpGUI, I did a theme called Kaaj Controls for it if you're interested search it on the BGRABitmap organization on GitHub.
« Last Edit: February 16, 2017, 12:32:56 am by lainz »

MarkECrum

  • Newbie
  • Posts: 2
Re: TBCImageButton: embed image file in exe
« Reply #4 on: May 05, 2017, 09:16:21 am »
Lainz, today I tried for hours to load a image from a Laz resourse file without success. Tonight I found this thread. With the method you gave... is this a Windows method only or will in work cross platform? I am very new to cross platform and really don't have ways to test so I'm just trying to clarify.

Thanks

lainz

  • Hero Member
  • *****
  • Posts: 1978
  • Nace una flor, todos los días sale el sol...
    • BGRABitmap
Re: TBCImageButton: embed image file in exe
« Reply #5 on: May 05, 2017, 02:54:11 pm »
Lainz, today I tried for hours to load a image from a Laz resourse file without success. Tonight I found this thread. With the method you gave... is this a Windows method only or will in work cross platform? I am very new to cross platform and really don't have ways to test so I'm just trying to clarify.

Thanks

I'm not sure. I tested it only under Windows. But I know that in order to use fpc resources (.res) you need to have some extra tools under linux.
http://wiki.freepascal.org/Lazarus_Resources#Checking_you_have_windres

MarkECrum

  • Newbie
  • Posts: 2
Re: TBCImageButton: embed image file in exe
« Reply #6 on: May 05, 2017, 09:08:19 pm »
Thanks LainZ,  here is what I have been working on. Just thought I'd show you.... I do have a question though with the first error. What causes that ImageButton to give this err? and what can I do to stop it? see pic...

I'm working on making the Button work as a checkbox or toggleBox. I use this quite often. Next I want to make it recieve the focus as well. I think that is the only thing that I would like it to do extra. Any suggestions on adding the Focus????

Thanks,
   Mark

lainz

  • Hero Member
  • *****
  • Posts: 1978
  • Nace una flor, todos los días sale el sol...
    • BGRABitmap
Re: TBCImageButton: embed image file in exe
« Reply #7 on: May 05, 2017, 10:53:03 pm »
Thanks LainZ,  here is what I have been working on. Just thought I'd show you.... I do have a question though with the first error. What causes that ImageButton to give this err? and what can I do to stop it? see pic...

I'm working on making the Button work as a checkbox or toggleBox. I use this quite often. Next I want to make it recieve the focus as well. I think that is the only thing that I would like it to do extra. Any suggestions on adding the Focus????

Thanks,
   Mark

I don't know, something wrong with gdb, or a path?

That's ok. Originally this component had checkbox mode, but I changed it a lot and forget to add it again. Is not so simple now because the fading animations, but hopefully you can do it.

If you finish it and want to give back I can test it and add it to bgracontrols, of course adding credits to your improvements.

And about the focus, you need to create a new copy of BCImageButton, and that inherits from TCustomControl and not from TGraphicControl- The only disadvantage of this is that transparency will not work for these kind of controls, all are opaque or with a solid background color. Also you need to add one of these:
- A new image for the focused state
- A method that allows customization of the focused drawings

Check TBCButtonFocus, I did that control based on TBCButton and that support focus.
« Last Edit: May 05, 2017, 10:55:09 pm by lainz »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus