 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
JD Guest
|
Posted: Sat Nov 29, 2003 12:12 pm Post subject: Re: strange exception while creating controls |
|
|
Maciej Komosinski <Maciej.Komosinski (AT) cs (DOT) put.poznan.pl> wrote:
| Quote: | [...] What is strange is that I discovered that there is no
exception when I hide the whole form first, then add
TListViews and TSplitters, and then show the form again!
Everything looks well then.
|
My experiance is that when I have encountered this same sort
of weird behavior, its always been caused by impropper memory
management elsewhere in my code. For example, using delete v/s
delete [] or vice versa or writting past the end of an allocated
block or inadvertantly dereferencing a pointer.
HTH
~ JD
|
|
| Back to top |
|
 |
Maciej Komosinski Guest
|
Posted: Sat Nov 29, 2003 12:24 pm Post subject: strange exception while creating controls |
|
|
Hello,
Please tell me what may be a reason for the exception EComponentError:
"A component named _1 already exists"?
My GUI is rather complicated, I have a TForm with a TFrame inside,
and many TListViews and TSplitters in the TFrame. This exception occurs
while adding TListViews and TSplitters to the TFrame (always in the
same moment, when adding the third TListView and the second TSplitter).
I created another simple test application and checked that there
is no such exception in my simple test program which uses similar
approach. The exception occurs only in my complex GUI.
What is strange is that I discovered that there is no exception
when I hide the whole form first, then add TListViews and TSplitters,
and then show the form again! Everything looks well then.
The reasons for this exception are very difficult to discover for me.
I am using BCB5, and CodeGuard did not discover any problems.
Please tell me, what are generally causes for this kind of
exception? (EComponentError: "A component named _1 already exists")?
Why there is "_1"? This may be some clue for me...
Thank you,
Maciej
|
|
| Back to top |
|
 |
Maciej Komosinski Guest
|
Posted: Sat Nov 29, 2003 10:50 pm Post subject: Re: strange exception while creating controls |
|
|
| Quote: | [...] What is strange is that I discovered that there is no
exception when I hide the whole form first, then add
TListViews and TSplitters, and then show the form again!
Everything looks well then.
My experiance is that when I have encountered this same sort
of weird behavior, its always been caused by impropper memory
management elsewhere in my code. For example, using delete v/s
delete [] or vice versa or writting past the end of an allocated
block or inadvertantly dereferencing a pointer.
|
I use CodeGuard, and anyway I am sure the code is OK,
because the non-GUI part has been tested thoroughly
for a few years.
I noticed that when I add the third TListView, everything
is fine until it is made Visible. In that moment I always
get this exception. If it is visible from the beginning,
then the exception occurs the first time it is modified
somehow (like ShowColumnHeaders is modified etc.)
When the third TListView is made visible, the stack looks like
myAddListView
TControl:SetVisible
TCustomListView:WndProc
TWinControl:UpdateControlState
TWinControl:CreateHandle
TCustomListView:CreateWnd
TStream:ReadComponent
TReader:ReadRootComponent
TComponent:SetName
TComponent:ValidateRename
EComponentError: "A component named _1 already exists"
is the TStream calls usual for just creating controls
by using listview=new TListView(this)?
Maybe somebody who knows VCL internals can tell when
such an exception may occur?
Thank you,
Maciej
|
|
| Back to top |
|
 |
Fishface Guest
|
Posted: Sun Nov 30, 2003 5:08 am Post subject: Re: strange exception while creating controls |
|
|
Maciej Komosinski wrote:
| Quote: | I created another simple test application and checked that there
is no such exception in my simple test program which uses similar
approach. The exception occurs only in my complex GUI.
|
Have you stepped through your code in the debugger? You can
debug right into the VCL source and find-out exactly what is causing
it.
The only time I have received a similar error is when I tried
dynamically creating multiple instances of a TFrame descendant.
They are somehow born with a non-unique name (at least in BCB5),
unlike a regular component. When added to the form's component list,
it throws the exception. I don't suppose you are doing anything like
that? The VCL wants each component of a of a given control to
have a unique name, or no name. When you add a control to your
frame or form, is it streamed or otherwise duplicated from and existing
control and as such have a name?
|
|
| Back to top |
|
 |
Fishface Guest
|
Posted: Sun Nov 30, 2003 7:40 am Post subject: Re: strange exception while creating controls |
|
|
Maciej Komosinski wrote:
| Quote: | I use CodeGuard, and anyway I am sure the code is OK,
because the non-GUI part has been tested thoroughly
for a few years.
|
Codeguard will let you get away with a multitude of VCL sins
if you build with runtime packages and don't use debug libraries
| Quote: | I noticed that when I add the third TListView, everything
is fine until it is made Visible. In that moment I always
get this exception. If it is visible from the beginning,
then the exception occurs the first time it is modified
somehow (like ShowColumnHeaders is modified etc.)
When the third TListView is made visible, the stack looks like
myAddListView
TControl:SetVisible
TCustomListView:WndProc
TWinControl:UpdateControlState
TWinControl:CreateHandle
TCustomListView:CreateWnd
TStream:ReadComponent
TReader:ReadRootComponent
TComponent:SetName
TComponent:ValidateRename
EComponentError: "A component named _1 already exists"
is the TStream calls usual for just creating controls
by using listview=new TListView(this)?
|
The call stack looks like the result of a call to RecreateWnd() of
either the form or the frame, not simply creating a component
Before your call to create the TListView, try dumping the
component list to a file and looking for something with a name.
TMemoryStream *stream1, *stream2;
stream1 = new TMemoryStream;
stream2 = new TMemoryStream;
stream1->WriteComponent(this);
stream1->Position = 0;
ObjectBinaryToText(stream1, stream2);
delete stream1;
stream2->SaveToFile("C:\dump.txt");
delete stream2;
I see you are making the form the Owner of the TListView.
It's not going on the frame, is it? Are you creating anything
dynamically in the frame's code and assigning the form as
the owner? If you are, and it is created when you drop
one on the at design time, it will be streamed with the form
as part of the components array. I don't know how it would
get the name, though. I'm just grasping at this point...
I could see a third *frame* causing an exception. If you
kept the default names, the frame would be given a name
of TFrame1. The first would have to be put on the form
at design time and the designer would name it TFrame11.
At runtime, if you create another, it would have the name
Frame1. A third would again have a name of Frame1,
which already exists and throws the exception. It's a bug
in BCB5, and I doubt very much if they fixed it, since they
didn't fix much else.
|
|
| Back to top |
|
 |
Maciej Komosinski Guest
|
Posted: Sun Nov 30, 2003 9:17 pm Post subject: Re: strange exception while creating controls |
|
|
| Quote: | I use CodeGuard, and anyway I am sure the code is OK,
because the non-GUI part has been tested thoroughly
for a few years.
Codeguard will let you get away with a multitude of VCL sins
if you build with runtime packages and don't use debug libraries
|
That's how I do.
| Quote: | ...
TReader:ReadRootComponent
TComponent:SetName
TComponent:ValidateRename
EComponentError: "A component named _1 already exists"
is the TStream calls usual for just creating controls
by using listview=new TListView(this)?
The call stack looks like the result of a call to RecreateWnd() of
either the form or the frame, not simply creating a component
Before your call to create the TListView, try dumping the
component list to a file and looking for something with a name.
...
stream2->SaveToFile("C:\dump.txt");
delete stream2;
I see you are making the form the Owner of the TListView.
It's not going on the frame, is it? Are you creating anything
dynamically in the frame's code and assigning the form as
the owner?
|
I create *everything* in runtime.
TForm is a parent and owner of some buttons and a single frame.
The TFrame is a parent and owner of some TListViews and TSplitters.
Adding more than two TListViews to the TFrame causes
the exception.
Here is the dump of the TFrame children:
After the first TListView is added:
object TFrame
...
object TListView
end
end
After the second one:
object TFrame
...
TabOrder = 0
object _1: TListView <-- what's this _1 ??
...
ViewStyle = vsReport
end
object TListView <-- ...and why there is no _something here?
...
ViewStyle = vsReport
end
end
....and the exception will happen soon!
So I expect the problem is with components Names.
I used
listview->Name=somethingunique;
to make names of each TListView unique and it works:
object TFrame
object TSplitter
object TSplitter
object TSplitter
object xx0: TListView
object xx1: TListView
object xx2: TListView
object xx3: TListView
end
Thank you very much for helping me with this problem.
I did not know I had to manually assign names. In the
documentation, borland says:
TControl::Name
Warning: Change control names only at design time.
so actually I should not directly modify names.
The other thing which is strange for me is that TSplitters
don't have names and TListView's have...
Yours,
Maciej
|
|
| Back to top |
|
 |
Fishface Guest
|
Posted: Mon Dec 01, 2003 2:52 am Post subject: Re: strange exception while creating controls |
|
|
Maciej Komosinski wrote:
Fishface wrote:
| Quote: | Codeguard will let you get away with a multitude of VCL sins
if you build with runtime packages and don't use debug libraries
That's how I do.
|
Here's a link:
http://groups.google.com/groups?selm=3e77667b%40newsgroups.borland.com
It gives you a false sense of security if it's not set-up just right.
| Quote: | I did not know I had to manually assign names.
|
I have never had to do this, and I tried all kinds of things like
creating several TListViews on form and a frame, and I did not
find any names being mysteriously assigned to the TListViews.
I'm baffled. Are you streaming properties, or a form layout?
Somehow, it's getting that name!
|
|
| Back to top |
|
 |
Maciej Komosinski Guest
|
Posted: Mon Dec 01, 2003 12:13 pm Post subject: Re: strange exception while creating controls |
|
|
| Quote: | I did not know I had to manually assign names.
I have never had to do this, and I tried all kinds of things like
creating several TListViews on form and a frame, and I did not
find any names being mysteriously assigned to the TListViews.
I'm baffled. Are you streaming properties, or a form layout?
Somehow, it's getting that name!
|
I am not streaming anything... just creating everything
in run-time, using new.
What is strange is that the exception DID NOT occur
in my test application, where I had TForm and TFrame
created as resources, and I only added TListViews and
TSplitters to the TFrame.
This made me think the problem is elsewhere, not in
adding subsequent TListViews.
BTW, I learned that I do not need to create unique
Names for TListViews, I just set all their Names to "".
Yours,
Maciej
|
|
| 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
|
|