TNotebook crash when page with name of an existing component is added at runtime
Original Reporter info from Mantis: wp @wpam
-
Reporter name:
Original Reporter info from Mantis: wp @wpam
- Reporter name:
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;
var
NewPage: TPage;
begin
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...
Mantis conversion info:
- Mantis ID: 36957
- Version: 2.1 (SVN)