View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0036957||Lazarus||Other||public||2020-04-23 12:30||2020-06-06 19:22|
|Product Version||2.1 (SVN)|
|Summary||0036957: TNotebook crash when page with name of an existing component is added at runtime|
|Description||At 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 Reproduce||Run 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 Information||The crash occurs in TUNBPages.AddObject:|
function TUNBPages.AddObject(const S: string; AObject: TObject): Integer;
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...
|Tags||No tags attached.|
|Fixed in Revision|
notebook_crash_duplicate_name.zip (1,868 bytes)
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.
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;
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...
notebook_crash_duplicate_name-v2.zip (2,001 bytes)
> 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.
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.
|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: notebook_crash_duplicate_name.zip|
|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: notebook_crash_duplicate_name-v2.zip|
|2020-04-23 16:19||Michal Gawrycki||Note Added: 0122365|
|2020-06-06 14:50||Bart Broersma||Note Added: 0123267|