View Issue Details

IDProjectCategoryView StatusLast Update
0036957LazarusOtherpublic2020-06-06 19:22
Reporterwp Assigned To 
Status newResolutionopen 
Product Version2.1 (SVN) 
Summary0036957: TNotebook crash when page with name of an existing component is added at runtime
DescriptionAt runtime, TNotebook pages can be added by calling its Pages.Add() with the name of the new page as a parameter. When here the name of an existing component is used the program crashes with the "Duplicate name" error message.
Steps To ReproduceRun attached demo. It contains a notebook having already two pages, a TEdit named "Edit1" and a button. The OnClick code of the button is supposed to add a new page to the notebook by calling "Notebook1.Pages.Add(Edit1.Text)". Since the text in Edit1 is equal to the name of the TEdit, the parameter of the Pages.Add call is the name of an already existing component.

The program crashes with this error message: "Duplicate name: A component named "Edit1" already exists".

Additional InformationThe crash occurs in TUNBPages.AddObject:

function TUNBPages.AddObject(const S: string; AObject: TObject): Integer;
  NewPage: TPage;
  Result := FPageList.Add(AObject);
  NewPage := TPage(AObject);
  if IsValidIdent(S) then NewPage.Name := S; // <--- crash here

Since the Name of a component must be unique, I think the Caption should not be reused as Name.

In unit CustomFormEditor, there is a "CreateUniqueComponentName", but this is not available at runtime...
TagsNo tags attached.
Fixed in Revision
Attached Files



2020-04-23 12:31

developer   ~0122355

Anton Kavalenka

2020-04-23 12:50

reporter   ~0122356

Last edited: 2020-04-23 12:53

View 2 revisions

Component names have to be unique inside single parent. That the way form editor works.
Is not the name of new component is entirely programmer responsibility.

Zeljan Rikalo

2020-04-23 14:15

developer   ~0122357

That's not good. If I want Edit1 as caption of my tabsheet that does not mean that name of tabsheet should be Edit1.
Maybe patch it as
if (csDesigning in ComponentState) and IsValidIdent(S) then NewPage.Name := S;


2020-04-23 14:51

developer   ~0122359

Added a new demo which displays the currently available page of the Notebook in a listbox.

Yes, after adding FNotebook to Componentstate ("if (csDesigning in FNotebook.ComponentState)...") the crash is gone. But when I query Notebook.Pages I get the tab *names* not the captions, i.e. the run-time added tabs have no names in the Pages list. At runtime I normally do not need the Name of component. Shouldn't Pages list the captions instead of the Names? Is this intended? Looks like a mess...

Michal Gawrycki

2020-04-23 16:19

reporter   ~0122365

> Shouldn't Pages list the captions instead of the Names?
IMHO names because property Pages should contain unique identifiers (like name). Each page can have the same caption so we can't identify them by caption.

Bart Broersma

2020-06-06 14:50

developer   ~0123267

I would think that is is the responsiblity of the programmer to ensure not having component name collissions?
Common practice is to not set component name when creating it @runtime.

Issue History

Date Modified Username Field Change
2020-04-23 12:30 wp New Issue
2020-04-23 12:31 wp Note Added: 0122355
2020-04-23 12:31 wp File Added:
2020-04-23 12:42 wp Additional Information Updated View Revisions
2020-04-23 12:42 wp LazTarget => -
2020-04-23 12:43 wp Additional Information Updated View Revisions
2020-04-23 12:50 Anton Kavalenka Note Added: 0122356
2020-04-23 12:53 Anton Kavalenka Note Edited: 0122356 View Revisions
2020-04-23 14:15 Zeljan Rikalo Note Added: 0122357
2020-04-23 14:51 wp Note Added: 0122359
2020-04-23 14:51 wp File Added:
2020-04-23 16:19 Michal Gawrycki Note Added: 0122365
2020-06-06 14:50 Bart Broersma Note Added: 0123267