Board index » cppbuilder » EResNotFound

EResNotFound


2003-08-04 06:53:42 AM
cppbuilder98
Hi,
I'm trying to create an instance of a TCustomForm derivative I wrote but
I get a Resource not found Exception when it attempts to create the
window. It has three bitmaps associated with it and they are include in
a .rc file in the package.
When attempting to use InitInheritedComponent(Self, TForm) internally it
barfs.
The odd thing is the error message says it cannot find the resource
"Classname". Is it looking for a .res file the same name as the class ?
I'm a bit blank on how you are "supposed" to handle these things.
Anyone go a few pointers. Oh the class I created is not a component as
I ran into problems doing that so am just trying to do it the other way
for now.
Craig
 
 

Re:EResNotFound

"Craig" < XXXX@XXXXX.COM >wrote in message
Quote
When attempting to use InitInheritedComponent(Self, TForm)
internally it barfs. The odd thing is the error message says it
cannot find the resource "Classname". Is it looking for a .res
file the same name as the class ?
It is looking in the executable's resources for a block of DFM data that has
the same name as the classname of the form being constructed. You need to
include a DFM for your descendant form class into the program's resources.
Did you do that?
Gambit
 

Re:EResNotFound

Hi Gambit,
Remy Lebeau (TeamB) wrote:
Quote
"Craig" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...


>When attempting to use InitInheritedComponent(Self, TForm)
>internally it barfs. The odd thing is the error message says it
>cannot find the resource "Classname". Is it looking for a .res
>file the same name as the class ?


It is looking in the executable's resources for a block of DFM data that has
the same name as the classname of the form being constructed. You need to
include a DFM for your descendant form class into the program's resources.
Did you do that?

err.. No
I wanted to create the thing on the fly. Obviously I have not
understood the process here properly. From your comments I take it you
need a DFM to construct the form. I'll have to look at someone elses
example to see what is required.
Thanks
Craig
 

{smallsort}

Re:EResNotFound

"Craig" < XXXX@XXXXX.COM >wrote in message
Quote
err.. No
A DFM is required for InitInheritedComponent() to work correctly.
Otherwise, do not use InitInheritedComponent() to begin with.
Quote
I wanted to create the thing on the fly.
You do not need InitInheritedComponent() for that. Just instantiate the
form directly:
TMyForm *form = new TMyForm(TheDesiredOwnerOrNULL);
// use form as needed
Gambit
 

Re:EResNotFound

Remy Lebeau (TeamB) wrote:
Quote
"Craig" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...


>err.. No


A DFM is required for InitInheritedComponent() to work correctly.
Otherwise, do not use InitInheritedComponent() to begin with.


>I wanted to create the thing on the fly.


You do not need InitInheritedComponent() for that. Just instantiate the
form directly:

TMyForm *form = new TMyForm(TheDesiredOwnerOrNULL);
// use form as needed

OK Now this is where it is interesting as thats what I am doing. The
only difference is I create the pointer when the class is instantiated.
I'm not sure whats causing the call to InitInheritedComponent(). I'll
have to step back a bit perhaps.
Craig
 

Re:EResNotFound

Gambit,
Just found this which seems to suggest theres a problem with trying to
create TCustomForm derivatives without a .dfm. This guy recommends
doing this: (Delphi sorry)
interface
// this form allows its any descendant to be created w/o DFM file
TRunTimeForm = class(TForm) // Run Time dfm-Indefendent form
public
constructor Create(AOwner: TComponent); override;
end; // TRunTimeForm
implementation
constructor TRunTimeForm.Create(AOwner: TComponent);
begin
GlobalNameSpace.BeginWrite;
try
inherited CreateNew(AOwner);
// resource-locating-loading part skipped
finally
GlobalNameSpace.EndWrite;
end;
end;
The whole article is here:
www.sklobovsky.com/community/threadmare/perks.htm
I'll try doing that and see what occurs.
Thanks Craig
 

Re:EResNotFound

Hi Ralph,
Works like a charm!
Thanks for that I'd have been looking for that for a while thats for sure!
Craig
Ralph Kazemier wrote:
Quote
"Craig" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>constructor TRunTimeForm.Create(AOwner: TComponent);
>begin
>GlobalNameSpace.BeginWrite;
>try
>inherited CreateNew(AOwner);
>// resource-locating-loading part skipped
>finally
>GlobalNameSpace.EndWrite;
>end;
>end;


You call should the c-tor of TCustomForm which takes two parameters;

__fastcall TCustomForm(Classes::TComponent* AOwner, int Dummy);

__fastcall TMyForm(TComponent* Owner):
TCustomForm(Owner,0) // any value is ignored
{
}


By calling this c-tor you achieve the same effect as seen in the Delphi code
(CreateNew). Have a look at the help pages for more information.


Ralph


 

Re:EResNotFound

"Craig" < XXXX@XXXXX.COM >wrote in message
Quote
constructor TRunTimeForm.Create(AOwner: TComponent);
begin
GlobalNameSpace.BeginWrite;
try
inherited CreateNew(AOwner);
// resource-locating-loading part skipped
finally
GlobalNameSpace.EndWrite;
end;
end;
You call should the c-tor of TCustomForm which takes two parameters;
__fastcall TCustomForm(Classes::TComponent* AOwner, int Dummy);
__fastcall TMyForm(TComponent* Owner):
TCustomForm(Owner,0) // any value is ignored
{
}
By calling this c-tor you achieve the same effect as seen in the Delphi code
(CreateNew). Have a look at the help pages for more information.
Ralph