Solved

Using ICON resources at runtime

Posted on 2000-04-24
9
175 Views
Last Modified: 2012-05-04
Hello...
I have  Icons.rc with content:
a ICON "tools2.ICO"
b ICON "keys.ICO"
c ICON "movie.ICO"

I have compiled and added it to the  project... as norma resource file... I can see all icons in exe file using icon extractor...

So, tell me please, how to extract the resource at runtime and adsign, for sample, to  TImage.picture

Thank you for your help.
Sandis Viksna.
0
Comment
Question by:sviksna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 15

Expert Comment

by:simonet
ID: 2743653
Here's an example of how to do it:

var
  ResDLLMod : Thandle;
begin

  ResDLLMod := LoadLibrary('resonly.dll');
  try
  // Always check if the module is loaded before
  // Trying to access it.
     if ResDLLMod=0 then
        raise Exception.Create('Cannont load resource library. Please check if RESONLY.DLL is in the application''s folder');
  image1.Picture.Icon.Handle := LoadIcon(ResDLLMod, 'RESEXPICON');
  finally  
    if ResDLLMod<>0 then
      FreeLibrary(ResDLLMod);
  end;
end;

RESEXPICON is the name of the icon resource as in the executable. If you're not accesing this in an external file, you can have everything in a single line (if the resources are in your executable):

  image1.Picture.Icon.Handle := LoadIcon(hInstance, 'a');

Yours,

Alex

0
 
LVL 15

Expert Comment

by:simonet
ID: 2743663
I meant my previous comment as an answer.

Yours,

Alex

0
 
LVL 1

Author Comment

by:sviksna
ID: 2743664
Yhanks, but i am using RES file... compiled in the same exe file...
all i need, i wna just get it out from there.. not from DLL file...

so, can u ansver for .res files?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
simonet earned 50 total points
ID: 2743674
Sure. It's just like I said in the last paragraph: if the resources are in the local exe (as opposed to an DLL or another EXE), you can simply use the line below to retrieve the icon resource:

image1.Picture.Icon.Handle := LoadIcon(hInstance, 'a');

Yours,

Alex
0
 
LVL 1

Author Comment

by:sviksna
ID: 2743678
I had heard about things like
TResourceStream and TFileStream;

there was some specification on create
but at runtime they shows some errors...

btw, it is in D4.. so everything should work...

help please

0
 
LVL 15

Expert Comment

by:simonet
ID: 2743692
You don't need to work with TResourceStream or TFileStream for that. Forget about them. LoadIcon works great.

What problems are you having? I've answered your question.

I can't tell what the problem is if I can't see your code or you give a detailed description of what you're doing.

Alex
0
 
LVL 1

Author Comment

by:sviksna
ID: 2743699
Well... thank you for so operative help:))) i were trying to solve this problem my own way very long time... thank you...

Sandis.
0
 
LVL 1

Author Comment

by:sviksna
ID: 2743701
What's about another type of images, like bitmap?
0
 
LVL 15

Expert Comment

by:simonet
ID: 2744011
Use LoadImage for that. LoadImage is documented in the Win32.hlp help file.

Alex
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question