Recent

Author Topic: [Solved] TrayIcon.Icon: load icon from lazarus resources  (Read 2288 times)

jex

  • New Member
  • *
  • Posts: 31
[Solved] TrayIcon.Icon: load icon from lazarus resources
« on: April 19, 2020, 02:19:12 am »
Hi,

I'm trying to load icon of TrayIcon from resouces, added the .ico files from Project Options -> Resources and compiled project.
When trying to change it with code
Code: Pascal  [Select][+][-]
  1. Form1.TrayIcon1.Icon.LoadFromLazarusResource('myico');
it returns an exception with "Resource myico not found".
I tried with and without .ico extension. File types in Resources is also ICON. Tried changing names from resources and nothing.

How to do that? ... and just in case it matters, I want it to be crossplatform.

Thank you
« Last Edit: April 19, 2020, 04:56:43 pm by jex »

jamie

  • Hero Member
  • *****
  • Posts: 7755
Re: TrayIcon.Icon: load icon from lazarus resources
« Reply #1 on: April 19, 2020, 12:43:31 pm »
I don't know where you got that method call from because I don't see it in the help file? Unless I am blind of course and that could be a possibility !  >:(

 Anyways, just use the standard resource method... LoadfromresourceID / name etc..

 the other targets should work fine that way.
The only true wisdom is knowing you know nothing

jex

  • New Member
  • *
  • Posts: 31
Re: TrayIcon.Icon: load icon from lazarus resources
« Reply #2 on: April 19, 2020, 02:14:59 pm »
Thanks. That seems to work with LoadFromResourceName.
And btw, LoadFromLazarusResource is in the autocomplete box in the IDE. It compiles but I wonder why it doesn't work...

----------
To future readers; I got it working by using
Code: Pascal  [Select][+][-]
  1. Form1.TrayIcon1.Icon.LoadFromResourceName(Hinstance,'yourico');
  2. // Note that icon name is the Resource name for that icon from Project Options > Resources.
  3. // To set Form icon also same method: Form1.Icon ....
« Last Edit: April 19, 2020, 02:17:31 pm by jex »

jamie

  • Hero Member
  • *****
  • Posts: 7755
Re: TrayIcon.Icon: load icon from lazarus resources
« Reply #3 on: April 19, 2020, 02:42:58 pm »
If you look in your settings you'll see that those types of resources aren't used but you could use them its only a setting, which is most likely why it didn't work...
The only true wisdom is knowing you know nothing

kveroneau

  • Full Member
  • ***
  • Posts: 124
Re: [Solved] TrayIcon.Icon: load icon from lazarus resources
« Reply #4 on: April 29, 2020, 12:49:15 am »
I had a similar issue, but instead of using the TrayIcon, I am trying to populate a TImageList using:
Code: Pascal  [Select][+][-]
  1. TImageList.AddLazarusResource

Not sure why these methods are public if they aren't supposed to be used, I ended up using the following method and it worked:
Code: Pascal  [Select][+][-]
  1. TImageList.AddResourceName

Worked like a charm.

Yes, I know you can add images via the GUI to a TImageList, but since I plan on using the same set of icons in multiple windows, I didn't want to add all the icons to many different TImageLists, as that would lead to duplication within the binary file and while the program is running.

 

TinyPortal © 2005-2018