Recent

Author Topic: Duplicate identifier error  (Read 4162 times)

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Duplicate identifier error
« Reply #15 on: February 26, 2023, 10:11:39 am »
Giving a component the name "Owner" can bring a project in a state in which it cannot be used any more without editing the lfm file:
  • Create a new project.
  • Add a button
  • Change its Name property to "Owner"
  • Compile --> Error: "Error: Duplicate identifier "Owner" - Identifier already defined in unit CLASSES: classesh.inc at line 1988".
  • Try to change the Name in the Object Inspector --> "'Owner' is already used by TReader/TWriter. Please choose another name."
The only way to recover the project is to save everyting, to close the IDE, and to change the occurence of "Owner" in the pas and the lfm files in an external editor. (It could also be done in the IDE itself, but I noticed that changes made to the lfm form are often lost by caching of the IDE).

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Duplicate identifier error
« Reply #16 on: February 26, 2023, 08:56:04 pm »
Giving a component the name "Owner" can bring a project in a state in which it cannot be used any more without editing the lfm file:
  • Create a new project.
  • Add a button
  • Change its Name property to "Owner"
  • Compile --> Error: "Error: Duplicate identifier "Owner" - Identifier already defined in unit CLASSES: classesh.inc at line 1988".
  • Try to change the Name in the Object Inspector --> "'Owner' is already used by TReader/TWriter. Please choose another name."
The only way to recover the project is to save everyting, to close the IDE, and to change the occurence of "Owner" in the pas and the lfm files in an external editor. (It could also be done in the IDE itself, but I noticed that changes made to the lfm form are often lost by caching of the IDE).
I can reproduce this, kinda corner case though. From scoping POV, I think this should be allowed despite may cause confusion, but the situation shouldn't be different from System.Close vs TCustomForm.Close, i.e.: identifier shadowing.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Duplicate identifier error
« Reply #17 on: February 26, 2023, 10:49:48 pm »
I can reproduce this, kinda corner case though. From scoping POV, I think this should be allowed despite may cause confusion, but the situation shouldn't be different from System.Close vs TCustomForm.Close, i.e.: identifier shadowing.
Delphi (7 PE) also disallows it with a rather cryptic errormessage.

Bart

 

TinyPortal © 2005-2018