Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using ICON resources at runtime

Posted on 2000-04-24
9
Medium Priority
?
178 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
Industry Leaders: 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 200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 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