BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Default instantiated form name in dfm: how to change?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (IDE)
View previous topic :: View next topic  
Author Message
Randall Parker
Guest





PostPosted: Sat Jan 03, 2004 8:00 am    Post subject: Default instantiated form name in dfm: how to change? Reply with quote



Using BCB v6 sp4 on Win2k.

My app has a form with class name of TAboutBox. I inherited this app and so what I'm
about to describe was not the result of any decisions on my part.

The .cpp file has a line:
TAboutBox *AboutBox

The .h file has:
extern PACKAGE TAboutBox *AboutBox;

What I want to do is to change AboutBox to MyAboutBox in order to see if I can avoid
some weird behavior where when at runtime when I click to open the about box I get
some standard default about box rather than my own about box. I suspect this display
of a wrong about box started happening when someone else I work with gave me a new
version of some component. But I'm not sure since I don't check the about box's
appearance very often.

My problem is that Changing my own source code to use MyAboutBox everywhere is not
sufficient to make this change. I need to change main cpp file but when I do that and
try to compile I get an error:
Undefined symbol 'MyAboutBox'

I figure this is because of the contents of the ddp file. Short of just editing the
contents of that file is there some correct way to change the name of the
instantiated pointer variable for a form so that that new name is used everywhere?

Does BCB want the object name to be the same as the class name without the leading T?

It seems to me that the way that BCB manages names of stuff that are created by the
IDE makes it hard to change names.

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Jan 03, 2004 9:31 am    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote




"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote in
message news:3ff67672$1 (AT) newsgroups (DOT) borland.com...

Quote:
What I want to do is to change AboutBox to MyAboutBox

Open the form's unit simply change the form's Name property via the Object
Inspector. Everything will be updated accordingly (well, not your actual
code that accesses the form via its name, you still have to do that
manually).

Quote:
I figure this is because of the contents of the ddp file.

No. The DDP file is merely a diagram of the form. The actual form name is
controlled by 1) the .cpp and .h file, and 2) the .dfm file.

Quote:
Does BCB want the object name to be the same as the class name without the
leading T?


Yes. When you change the Name property, the 'T' is appended to the new name
and then used as the new class name.


Gambit



Back to top
Randall Parker
Guest





PostPosted: Sat Jan 03, 2004 6:22 pm    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote



Remy,

Okay, I changed the class name per your instructions. Now after compiling and linking
when it goes to run I getL

Project MyProject.exe raised exception class EResNotFound with message 'Resource
TPxgAboutBox not found'. Process stopped. Use Step or Run to continue.

Yet I know this is part of the project because in the list that comes up from
chooising Project | Add To Project or Project | Remove from Project it shows up
there. I've even removed the source file and added it back in and it comes in with
the right class name to the right of it if I go back to the Add or Remove project
dialog and look at it there.

So why isn't this working? Any idea?

I even switched to a different project (since I have one for building with CodeGuard
and one without) and got the same problem there. So I haven't munged the bpr file of
the one project where I originally encountered and worked on the problem with showing
the wrong about box.

Remy Lebeau (TeamB) wrote:

Quote:
"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote in
message news:3ff67672$1 (AT) newsgroups (DOT) borland.com...


What I want to do is to change AboutBox to MyAboutBox


Open the form's unit simply change the form's Name property via the Object
Inspector. Everything will be updated accordingly (well, not your actual
code that accesses the form via its name, you still have to do that
manually).


I figure this is because of the contents of the ddp file.


No. The DDP file is merely a diagram of the form. The actual form name is
controlled by 1) the .cpp and .h file, and 2) the .dfm file.


Does BCB want the object name to be the same as the class name without the

leading T?

Yes. When you change the Name property, the 'T' is appended to the new name
and then used as the new class name.


Gambit




Back to top
Randall Parker
Guest





PostPosted: Sat Jan 03, 2004 6:52 pm    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote

Okay, I've renamed using the Name in the Properties list and then I got this error:

Project MyProject.exe raised exception class EResNotFound with message 'Resource
TPxgAboutBox not found'. Process stopped. Use Step or Run to continue.

Then I renamed again to XXXAboutBox and was still getting an error. I saw that in my
main .cpp file the WINAPI WinMain routine and the USEFORM statements above it were
still calling out the previous name. So I deleted the rows that called out the
previous name. Then I could build and my app would start without crashing. But if I
selected the Help About item it caused an access violation.

I tried deleting and adding the About.cpp file that contains the TXXXAboutBox class
and that operation works okay. But it does not cause the main .cpp file to get the
USEFORM or Application->CreateForm statements for that class's default object
XXXAboutBox.

So at this point I think maybe I'm stuck with something about the About.cpp's dfm
file being munged? Is that possible? Or the bpr file has a problem?

I need something to try. Any suggestions?


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Jan 03, 2004 8:52 pm    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote

"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote in
message news:3ff70f72$1 (AT) newsgroups (DOT) borland.com...

Quote:
Project MyProject.exe raised exception class EResNotFound
with message 'Resource TPxgAboutBox not found'. Process
stopped. Use Step or Run to continue.

It should have worked fine the first time.

Quote:
Then I renamed again to XXXAboutBox and was still getting
an error. I saw that in my main .cpp file the WINAPI WinMain
routine and the USEFORM statements above it were still calling
out the previous name.

Your eartlier manual editing probably somehow disassociated the code with
the IDE such that it couldn't find the references anymore to change them
automatically.

Quote:
So I deleted the rows that called out the previous name.

You should not have delated them, simply changed them to match the new name.

Quote:
Then I could build and my app would start without crashing. But
if I selected the Help About item it caused an access violation.

As well you should, since it sounds like you removed the code that was
needed to instantiate the form instance, theus you tried to access an
invalid pointer at runtime.

Quote:
I tried deleting and adding the About.cpp file that contains the
TXXXAboutBox class
and that operation works okay. But it does not cause the main .cpp file to
get the
USEFORM or Application->CreateForm statements for that class's default
object
XXXAboutBox.

After adding the unit to the project, did you go into the Project Options
and add the form to the AutoCreate list? Earlier, you said that you were
using BCB6. Secondary forms are no longer auto-created, only the MainForm
is. If you want a secondary form to be auto-created, you have to set it up
manually. Otherwise, you should write your code to dynamically instantiate
the form when actually needed at runtime.


Gambit



Back to top
Randall Parker
Guest





PostPosted: Sat Jan 03, 2004 9:14 pm    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote

Remy Lebeau (TeamB) wrote:

Quote:
After adding the unit to the project, did you go into the Project Options
and add the form to the AutoCreate list?

It is there.

Quote:
Earlier, you said that you were
using BCB6. Secondary forms are no longer auto-created, only the MainForm
is. If you want a secondary form to be auto-created, you have to set it up
manually. Otherwise, you should write your code to dynamically instantiate
the form when actually needed at runtime.

At this point I've removed the latest about fox from the project and then copied in
an older version of my About.cpp and About.h and .ddp and .dfm files from another
directory and added it to the project.

If I show the about box I get some default other about box which comes from I do not
know where.

If I rename my about box to AboutYYYBox then my app links and starts up. If I do Help
Quote:
About I execute the AboutYYYBox->ShowModal(); and then get an access violation.

But here is the twist: adding in the old about box gave me the USEFORM and
Application->CreateForm statements. THe CreateForm even does the
(__classid(TAboutYYYBox),&AboutYYYBox) as arguments. So that part is correct.

Also, I checked the auto-create list and, yes, AboutYYYBox is on it.

So I can not figure out what this thing is doing.

Quote:


Gambit




Back to top
Randall Parker
Guest





PostPosted: Sat Jan 03, 2004 9:37 pm    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote

Gambit,

The problem has gotten weirder still:

1) I now can build and run the app and it starts up okay. But the problem that I'm
having with access violations is not due to an uninitialized form pointer. I set a
breakpoint on the OnClick event of the menu item and I do not even get to the menu
item breakpoint on its very first line before the I get:
Access vilation at address 004DF4FF in module 'MyApp.exe', Read of address 00000000.

(not the real app exe name btw)

So where is this access violation coming from?

I went and added another menu item to the Help menu list after the About item. I
added the same ShowModal statement there. Actually, I create a new blank form (I was
about to lay out a complete new About box from scratch) (Called it XXXWhatAbout) and
decided to show it first. That form does not show up (and, yes, it is on the
auto-create list too).

So I'm getting an access violation somewhere. It is not crashing my app. I can't get
to a Call Tree to see it since clicking OK on the error dialog box returns me to a
functional app.

Back to top
Randall Parker
Guest





PostPosted: Sat Jan 03, 2004 10:14 pm    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote

Update on my previous report: I do not trust that my debugger breakpoint is really
working. I commented out the OnClick's code where the debugger breakpoint was set.
That was enough to prevent the access violation message. So it is acting like the
debugger breakpoint is being ignored.

BTW, I'm compiled unoptimized with full debugger info and have been debugging without
problems for months.

So next I added a new pop-down menu list, a new list item, and did an OnClick there.
It has the same problem and the breakpoint doesn't stop in it either.

So next I went into that new OnClick and made my own local version of the new About
form (and I assigned its pointer to the global variable for that form that should
have been set at start-up), showed it, and then deleted it. Running that now works.
So the real problem here is that even with the new added form it is not getting
created when the app starts.

I've tried removing and adding back into the auto-start list the new form and it
didn't help any.

Any other ideas on what is causing this?


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Jan 03, 2004 10:20 pm    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote

"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote in
message news:3ff73081$1 (AT) newsgroups (DOT) borland.com...

Quote:
If I rename my about box to AboutYYYBox then my app
links and starts up. If I do Help | About I execute the
AboutYYYBox->ShowModal(); and then get an access violation.

Then please show your actual code, you are still doing something wrong with
it. An AV occurs from accessing invalid memory. If all you are doing is
calling ShowModal() and nothing else, then the only way you can get an AV
with what you have described is if your AboutYYYBox pointer is not assigned
to a valid form instance. Are you, by chance, declaring a local variable
inside your "About" menu item's OnClick handler?


Gambit



Back to top
Randall Parker
Guest





PostPosted: Sat Jan 03, 2004 11:04 pm    Post subject: Re: Default instantiated form name in dfm: how to change? Reply with quote

Remy,

Update:

1) My old About form causes raised exception class EResNotFound with message
'Resource TAboutYYYBox not found' on start-up. So it can not find the resource. I
have to entirely remove my old About form .cpp (used Project | Remove from Project...
to do so) from the project in order to be able to start my app.

2) Here is what had me confused on the old form: I had two main .cpp files. One was
in the main build directory where the .bpr is located. But I noticed one had been
created some time in the last several hours in the directory where the source is
located. That other main .cpp file was allowing the app to start up and find the old
about form's resources. I deleted it and now I'm back to the error I'd run into
earlier where it can not find the resources for that file.

3) I'm trying to do a Build All and it is telling me it can't find that main .cpp
file in the path for where all the source is located. Well, it is not supposed to be
there, I've deleted it from there, and it exists in the directory where the .bpr file
is located. What to do about that? Can I remove my main .cpp file from the project
and then just add it right back in again? It only shows up once in the Project list
when one gets the Remove From Project dialog.

4) My new WhatAbout form works okay. I can invoke it with ShowModal() and it shows.
So its pointer does get initialized properly and does not cause an exception when I
try to invoke it.

The Click event routine is a single line and declares no local variable.

voic __fastcall TFigures::About1Click(TObject *Sender)
{
//AboutYYYBox->ShowModal(); // Old About form.
WhatAboutBox->ShowModal(); // New About form.
}

I have to have the AboutYYYBox entirely out of the project to be able to run it. So
the first call to to the old form is now commented out.

But with my old form pointer AboutYYYBox (class TAboutYYYBox) now I can not even
start the app up if I have it referenced. It compiles and links okay. But when the
exe is run I get the .

5) Breakpoints are not being hit anywhere in my app at all now.
This is my worst problem at this point. I can reconstruct and use a new About
form. But I need to be able to debug.

6) If I was going to create a new project for my program from scratch (which seems
like it might be a good idea at this point) then how would I tell it to start with
the existing main .cpp file? Or would I not even want to use the existing main .cpp
file? Would I just delete the .bpr file from the dir and make a new project file in
that dir ignoring all else in that dir while I include all the sources from the
source dirs?


Remy Lebeau (TeamB) wrote:

Quote:
"Randall Parker" <STOPtechiepundit (AT) EVILfuturePOXpunditSPAM (DOT) com> wrote in
message news:3ff73081$1 (AT) newsgroups (DOT) borland.com...


If I rename my about box to AboutYYYBox then my app
links and starts up. If I do Help | About I execute the
AboutYYYBox->ShowModal(); and then get an access violation.


Then please show your actual code, you are still doing something wrong with
it. An AV occurs from accessing invalid memory. If all you are doing is
calling ShowModal() and nothing else, then the only way you can get an AV
with what you have described is if your AboutYYYBox pointer is not assigned
to a valid form instance. Are you, by chance, declaring a local variable
inside your "About" menu item's OnClick handler?


Gambit




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (IDE) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.