How to load PNG file into my custom component? Cannot get correct instance
up vote
0
down vote
favorite
I want to create a custom control (from TPanel) that holds some TImages.
I want to display PNG (with transparency) into those mages. Therefore, I am TRYING to attach the PNG via IDE's "Resource and Images" to the package.
The problem is that when I put the component into a test application it will fail on MyPng->LoadFromResourceName
line with "resource not found". Interestingly, if I add the PNG as a resource to the test application, it will work.
This means that the component is looking into the wrong module for the PNG resource.
I print the instance with ShowMessage it shows indeed "ComponentTester.exe".
__fastcall TVolumeCtrl::TVolumeCtrl(TComponent* Owner)
: TPanel(Owner)
{
HINST h = FindClassHInstance(__classid(TVolumeCtrl));
ShowMessage(GetModuleName(h));
TPngImage *Png3 = new TPngImage();
MyPng->LoadFromResourceName(h, "Btn1");
How to get the correct instance?
Note: The PNG files ARE compiled into the RES file generated. I looked inside with a Hex viewer.
c++ c++builder
add a comment |
up vote
0
down vote
favorite
I want to create a custom control (from TPanel) that holds some TImages.
I want to display PNG (with transparency) into those mages. Therefore, I am TRYING to attach the PNG via IDE's "Resource and Images" to the package.
The problem is that when I put the component into a test application it will fail on MyPng->LoadFromResourceName
line with "resource not found". Interestingly, if I add the PNG as a resource to the test application, it will work.
This means that the component is looking into the wrong module for the PNG resource.
I print the instance with ShowMessage it shows indeed "ComponentTester.exe".
__fastcall TVolumeCtrl::TVolumeCtrl(TComponent* Owner)
: TPanel(Owner)
{
HINST h = FindClassHInstance(__classid(TVolumeCtrl));
ShowMessage(GetModuleName(h));
TPngImage *Png3 = new TPngImage();
MyPng->LoadFromResourceName(h, "Btn1");
How to get the correct instance?
Note: The PNG files ARE compiled into the RES file generated. I looked inside with a Hex viewer.
c++ c++builder
@DavidHeffernan - FindClassHInstance returns "ComponentTester.exe". ComponentTester does not contains the resource.
– Rigel
Nov 8 at 10:18
note: I don't drop the TVolumeCtrl component from the palette into ComponentTester's form. I create TVolumeCtrl at runtime:new TVolumeCtrl(this)
. But I don't think this is relevant to the problem.
– Rigel
Nov 8 at 10:20
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to create a custom control (from TPanel) that holds some TImages.
I want to display PNG (with transparency) into those mages. Therefore, I am TRYING to attach the PNG via IDE's "Resource and Images" to the package.
The problem is that when I put the component into a test application it will fail on MyPng->LoadFromResourceName
line with "resource not found". Interestingly, if I add the PNG as a resource to the test application, it will work.
This means that the component is looking into the wrong module for the PNG resource.
I print the instance with ShowMessage it shows indeed "ComponentTester.exe".
__fastcall TVolumeCtrl::TVolumeCtrl(TComponent* Owner)
: TPanel(Owner)
{
HINST h = FindClassHInstance(__classid(TVolumeCtrl));
ShowMessage(GetModuleName(h));
TPngImage *Png3 = new TPngImage();
MyPng->LoadFromResourceName(h, "Btn1");
How to get the correct instance?
Note: The PNG files ARE compiled into the RES file generated. I looked inside with a Hex viewer.
c++ c++builder
I want to create a custom control (from TPanel) that holds some TImages.
I want to display PNG (with transparency) into those mages. Therefore, I am TRYING to attach the PNG via IDE's "Resource and Images" to the package.
The problem is that when I put the component into a test application it will fail on MyPng->LoadFromResourceName
line with "resource not found". Interestingly, if I add the PNG as a resource to the test application, it will work.
This means that the component is looking into the wrong module for the PNG resource.
I print the instance with ShowMessage it shows indeed "ComponentTester.exe".
__fastcall TVolumeCtrl::TVolumeCtrl(TComponent* Owner)
: TPanel(Owner)
{
HINST h = FindClassHInstance(__classid(TVolumeCtrl));
ShowMessage(GetModuleName(h));
TPngImage *Png3 = new TPngImage();
MyPng->LoadFromResourceName(h, "Btn1");
How to get the correct instance?
Note: The PNG files ARE compiled into the RES file generated. I looked inside with a Hex viewer.
c++ c++builder
c++ c++builder
edited Nov 9 at 12:43
asked Nov 8 at 9:49
Rigel
9,71714110217
9,71714110217
@DavidHeffernan - FindClassHInstance returns "ComponentTester.exe". ComponentTester does not contains the resource.
– Rigel
Nov 8 at 10:18
note: I don't drop the TVolumeCtrl component from the palette into ComponentTester's form. I create TVolumeCtrl at runtime:new TVolumeCtrl(this)
. But I don't think this is relevant to the problem.
– Rigel
Nov 8 at 10:20
add a comment |
@DavidHeffernan - FindClassHInstance returns "ComponentTester.exe". ComponentTester does not contains the resource.
– Rigel
Nov 8 at 10:18
note: I don't drop the TVolumeCtrl component from the palette into ComponentTester's form. I create TVolumeCtrl at runtime:new TVolumeCtrl(this)
. But I don't think this is relevant to the problem.
– Rigel
Nov 8 at 10:20
@DavidHeffernan - FindClassHInstance returns "ComponentTester.exe". ComponentTester does not contains the resource.
– Rigel
Nov 8 at 10:18
@DavidHeffernan - FindClassHInstance returns "ComponentTester.exe". ComponentTester does not contains the resource.
– Rigel
Nov 8 at 10:18
note: I don't drop the TVolumeCtrl component from the palette into ComponentTester's form. I create TVolumeCtrl at runtime:
new TVolumeCtrl(this)
. But I don't think this is relevant to the problem.– Rigel
Nov 8 at 10:20
note: I don't drop the TVolumeCtrl component from the palette into ComponentTester's form. I create TVolumeCtrl at runtime:
new TVolumeCtrl(this)
. But I don't think this is relevant to the problem.– Rigel
Nov 8 at 10:20
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The only explanation that makes sense is that you are not using runtime packages. So you aren't loading the module that contains the resource.
The right way to link the resource for the component is to use a $R
directive in the source file that declares the type, TVolumeCtrl
in this case. That way the resource will be linked to whichever module contains the implementation of TVolumeCtrl
. That's going to be a package when you are compiling the runtime package (which is used at designtime by your designtime package), and it will be the executable when you compile an executable that does not use runtime packages.
In my tester app, the "link with runtime packages" is checked. And in "packages" in "design packages" the BPL that contains my component is checked also.
– Rigel
Nov 8 at 10:28
I let the IDE do all those resource compiling and linking. But I will try to link it also manually with $R as you say. Maybe there is a bug in the IDE's "Resources and images"?
– Rigel
Nov 8 at 10:30
I looked with Process Viewer into the tester app while it was running. Indeed it does not load my BPL! So, the project is set to use the BPL as runtime package but it doesn't.
– Rigel
Nov 8 at 10:34
There is no bug with the IDE's resources and images feature. It's just the wrong way to do what you are trying to do. Think about it. You've linked the resource to the package, but then you aren't using the package. If you were using the package thenFindClassHInstance
would return the module representing the package. Clearly you are linking the package into your executable. Even if you intended to link using runtime packages, your code should support both modes of operation: namely runtime packages and static linking.
– David Heffernan
Nov 8 at 10:52
You are right. The exe was not using the runtime package. It seems that it is not enough to add the BPI package into the "Runtime packages" list. I also needed to add the BPI file to the project (in Proj manager).
– Rigel
Nov 8 at 11:00
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The only explanation that makes sense is that you are not using runtime packages. So you aren't loading the module that contains the resource.
The right way to link the resource for the component is to use a $R
directive in the source file that declares the type, TVolumeCtrl
in this case. That way the resource will be linked to whichever module contains the implementation of TVolumeCtrl
. That's going to be a package when you are compiling the runtime package (which is used at designtime by your designtime package), and it will be the executable when you compile an executable that does not use runtime packages.
In my tester app, the "link with runtime packages" is checked. And in "packages" in "design packages" the BPL that contains my component is checked also.
– Rigel
Nov 8 at 10:28
I let the IDE do all those resource compiling and linking. But I will try to link it also manually with $R as you say. Maybe there is a bug in the IDE's "Resources and images"?
– Rigel
Nov 8 at 10:30
I looked with Process Viewer into the tester app while it was running. Indeed it does not load my BPL! So, the project is set to use the BPL as runtime package but it doesn't.
– Rigel
Nov 8 at 10:34
There is no bug with the IDE's resources and images feature. It's just the wrong way to do what you are trying to do. Think about it. You've linked the resource to the package, but then you aren't using the package. If you were using the package thenFindClassHInstance
would return the module representing the package. Clearly you are linking the package into your executable. Even if you intended to link using runtime packages, your code should support both modes of operation: namely runtime packages and static linking.
– David Heffernan
Nov 8 at 10:52
You are right. The exe was not using the runtime package. It seems that it is not enough to add the BPI package into the "Runtime packages" list. I also needed to add the BPI file to the project (in Proj manager).
– Rigel
Nov 8 at 11:00
|
show 1 more comment
up vote
1
down vote
accepted
The only explanation that makes sense is that you are not using runtime packages. So you aren't loading the module that contains the resource.
The right way to link the resource for the component is to use a $R
directive in the source file that declares the type, TVolumeCtrl
in this case. That way the resource will be linked to whichever module contains the implementation of TVolumeCtrl
. That's going to be a package when you are compiling the runtime package (which is used at designtime by your designtime package), and it will be the executable when you compile an executable that does not use runtime packages.
In my tester app, the "link with runtime packages" is checked. And in "packages" in "design packages" the BPL that contains my component is checked also.
– Rigel
Nov 8 at 10:28
I let the IDE do all those resource compiling and linking. But I will try to link it also manually with $R as you say. Maybe there is a bug in the IDE's "Resources and images"?
– Rigel
Nov 8 at 10:30
I looked with Process Viewer into the tester app while it was running. Indeed it does not load my BPL! So, the project is set to use the BPL as runtime package but it doesn't.
– Rigel
Nov 8 at 10:34
There is no bug with the IDE's resources and images feature. It's just the wrong way to do what you are trying to do. Think about it. You've linked the resource to the package, but then you aren't using the package. If you were using the package thenFindClassHInstance
would return the module representing the package. Clearly you are linking the package into your executable. Even if you intended to link using runtime packages, your code should support both modes of operation: namely runtime packages and static linking.
– David Heffernan
Nov 8 at 10:52
You are right. The exe was not using the runtime package. It seems that it is not enough to add the BPI package into the "Runtime packages" list. I also needed to add the BPI file to the project (in Proj manager).
– Rigel
Nov 8 at 11:00
|
show 1 more comment
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The only explanation that makes sense is that you are not using runtime packages. So you aren't loading the module that contains the resource.
The right way to link the resource for the component is to use a $R
directive in the source file that declares the type, TVolumeCtrl
in this case. That way the resource will be linked to whichever module contains the implementation of TVolumeCtrl
. That's going to be a package when you are compiling the runtime package (which is used at designtime by your designtime package), and it will be the executable when you compile an executable that does not use runtime packages.
The only explanation that makes sense is that you are not using runtime packages. So you aren't loading the module that contains the resource.
The right way to link the resource for the component is to use a $R
directive in the source file that declares the type, TVolumeCtrl
in this case. That way the resource will be linked to whichever module contains the implementation of TVolumeCtrl
. That's going to be a package when you are compiling the runtime package (which is used at designtime by your designtime package), and it will be the executable when you compile an executable that does not use runtime packages.
answered Nov 8 at 10:28
David Heffernan
511k338031195
511k338031195
In my tester app, the "link with runtime packages" is checked. And in "packages" in "design packages" the BPL that contains my component is checked also.
– Rigel
Nov 8 at 10:28
I let the IDE do all those resource compiling and linking. But I will try to link it also manually with $R as you say. Maybe there is a bug in the IDE's "Resources and images"?
– Rigel
Nov 8 at 10:30
I looked with Process Viewer into the tester app while it was running. Indeed it does not load my BPL! So, the project is set to use the BPL as runtime package but it doesn't.
– Rigel
Nov 8 at 10:34
There is no bug with the IDE's resources and images feature. It's just the wrong way to do what you are trying to do. Think about it. You've linked the resource to the package, but then you aren't using the package. If you were using the package thenFindClassHInstance
would return the module representing the package. Clearly you are linking the package into your executable. Even if you intended to link using runtime packages, your code should support both modes of operation: namely runtime packages and static linking.
– David Heffernan
Nov 8 at 10:52
You are right. The exe was not using the runtime package. It seems that it is not enough to add the BPI package into the "Runtime packages" list. I also needed to add the BPI file to the project (in Proj manager).
– Rigel
Nov 8 at 11:00
|
show 1 more comment
In my tester app, the "link with runtime packages" is checked. And in "packages" in "design packages" the BPL that contains my component is checked also.
– Rigel
Nov 8 at 10:28
I let the IDE do all those resource compiling and linking. But I will try to link it also manually with $R as you say. Maybe there is a bug in the IDE's "Resources and images"?
– Rigel
Nov 8 at 10:30
I looked with Process Viewer into the tester app while it was running. Indeed it does not load my BPL! So, the project is set to use the BPL as runtime package but it doesn't.
– Rigel
Nov 8 at 10:34
There is no bug with the IDE's resources and images feature. It's just the wrong way to do what you are trying to do. Think about it. You've linked the resource to the package, but then you aren't using the package. If you were using the package thenFindClassHInstance
would return the module representing the package. Clearly you are linking the package into your executable. Even if you intended to link using runtime packages, your code should support both modes of operation: namely runtime packages and static linking.
– David Heffernan
Nov 8 at 10:52
You are right. The exe was not using the runtime package. It seems that it is not enough to add the BPI package into the "Runtime packages" list. I also needed to add the BPI file to the project (in Proj manager).
– Rigel
Nov 8 at 11:00
In my tester app, the "link with runtime packages" is checked. And in "packages" in "design packages" the BPL that contains my component is checked also.
– Rigel
Nov 8 at 10:28
In my tester app, the "link with runtime packages" is checked. And in "packages" in "design packages" the BPL that contains my component is checked also.
– Rigel
Nov 8 at 10:28
I let the IDE do all those resource compiling and linking. But I will try to link it also manually with $R as you say. Maybe there is a bug in the IDE's "Resources and images"?
– Rigel
Nov 8 at 10:30
I let the IDE do all those resource compiling and linking. But I will try to link it also manually with $R as you say. Maybe there is a bug in the IDE's "Resources and images"?
– Rigel
Nov 8 at 10:30
I looked with Process Viewer into the tester app while it was running. Indeed it does not load my BPL! So, the project is set to use the BPL as runtime package but it doesn't.
– Rigel
Nov 8 at 10:34
I looked with Process Viewer into the tester app while it was running. Indeed it does not load my BPL! So, the project is set to use the BPL as runtime package but it doesn't.
– Rigel
Nov 8 at 10:34
There is no bug with the IDE's resources and images feature. It's just the wrong way to do what you are trying to do. Think about it. You've linked the resource to the package, but then you aren't using the package. If you were using the package then
FindClassHInstance
would return the module representing the package. Clearly you are linking the package into your executable. Even if you intended to link using runtime packages, your code should support both modes of operation: namely runtime packages and static linking.– David Heffernan
Nov 8 at 10:52
There is no bug with the IDE's resources and images feature. It's just the wrong way to do what you are trying to do. Think about it. You've linked the resource to the package, but then you aren't using the package. If you were using the package then
FindClassHInstance
would return the module representing the package. Clearly you are linking the package into your executable. Even if you intended to link using runtime packages, your code should support both modes of operation: namely runtime packages and static linking.– David Heffernan
Nov 8 at 10:52
You are right. The exe was not using the runtime package. It seems that it is not enough to add the BPI package into the "Runtime packages" list. I also needed to add the BPI file to the project (in Proj manager).
– Rigel
Nov 8 at 11:00
You are right. The exe was not using the runtime package. It seems that it is not enough to add the BPI package into the "Runtime packages" list. I also needed to add the BPI file to the project (in Proj manager).
– Rigel
Nov 8 at 11:00
|
show 1 more comment
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205173%2fhow-to-load-png-file-into-my-custom-component-cannot-get-correct-instance%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@DavidHeffernan - FindClassHInstance returns "ComponentTester.exe". ComponentTester does not contains the resource.
– Rigel
Nov 8 at 10:18
note: I don't drop the TVolumeCtrl component from the palette into ComponentTester's form. I create TVolumeCtrl at runtime:
new TVolumeCtrl(this)
. But I don't think this is relevant to the problem.– Rigel
Nov 8 at 10:20