 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Josh Guest
|
Posted: Tue Jan 09, 2007 9:15 pm Post subject: HELP: Loading bitmaps from a res file within component |
|
|
I have a few new components that require bitmaps to be displayed in TImage
controls within my component. The component works fine when I load the
files from their path names but when I try to load from a resource file it
can never find them either by name or ID.
Here is some code on how I'm doing this.
#include <vcl.h>
#pragma hdrstop
#include "TLED.h"
#pragma resource "LED.res"
#pragma package(smart_init)
__fastcall TLED::TLED(TComponent* Owner)
: TImage(Owner)
{
this->Width = 16;
this->Height = 16;
this->Transparent = true;
this->Picture->Bitmap->LoadFromResourceName((int) HInstance,"LED_DARK");
}
void TLED::SetGreen()
{
this->Picture->Bitmap->LoadFromResourceName((int)HInstance,"LED_GREEN");
}
I am unsure where the component actually looks for the resources. Is it in
the package resource file, application resource file where the component is
dropped on a form, a separate resource for the control?
I know I'm missing something simple here.
Thanks in advance,
Josh |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 10, 2007 2:08 am Post subject: Re: Loading bitmaps from a res file within component |
|
|
"Josh" <jarnold (AT) atterotech (DOT) com> wrote in message
news:45a3b15d (AT) newsgroups (DOT) borland.com...
| Quote: | when I try to load from a resource file it can never find them
either by name or ID. |
That is because you are trying to load them from the wrong place. For
a component to load an image from its own resources, you need to use
the FindClassHInstance() function instead of the global HInstance
variable, ie:
this->Picture->Bitmap->LoadFromResourceName(FindClassHInstance(__class
id(TLED)), "LED_DARK");
this->Picture->Bitmap->LoadFromResourceName(FindClassHInstance(__class
id(TLED)), "LED_GREEN");
Gambit |
|
| Back to top |
|
 |
Josh Guest
|
Posted: Wed Jan 10, 2007 3:28 am Post subject: Re: Loading bitmaps from a res file within component |
|
|
Remy,
Thanks for the suggestion however, using FindClassHInstance did not solve my
problem. I still get an EResNotFound exception.
One thing I didn't mention and am unsure of the effect. I need to build
without dynamic RTL and without runtime packages.
How does this affect where I get my resources for the component I'm trying
to use?
Thanks,
Josh
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:45a3f5fd$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"Josh" <jarnold (AT) atterotech (DOT) com> wrote in message
news:45a3b15d (AT) newsgroups (DOT) borland.com...
when I try to load from a resource file it can never find them
either by name or ID.
That is because you are trying to load them from the wrong place. For
a component to load an image from its own resources, you need to use
the FindClassHInstance() function instead of the global HInstance
variable, ie:
this->Picture->Bitmap->LoadFromResourceName(FindClassHInstance(__class
id(TLED)), "LED_DARK");
this->Picture->Bitmap->LoadFromResourceName(FindClassHInstance(__class
id(TLED)), "LED_GREEN");
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 10, 2007 11:46 am Post subject: Re: Loading bitmaps from a res file within component |
|
|
"Josh" <jarnold (AT) atterotech (DOT) com> wrote in message
news:45a408c2$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Thanks for the suggestion however, using FindClassHInstance did
not solve my problem. I still get an EResNotFound exception.
|
Then your images are likely not part of the component package's
resources to begin with. How exactly are you adding them to your
project? FindClassHInstance() is the proper way to locate an image
that belongs to a package.
Gambit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|