Recent

Author Topic: Compilation error when the TComponentName matches the unit name.  (Read 633 times)

dmitryb

  • Jr. Member
  • **
  • Posts: 69
Hello everyone.

I have a suspicion that in one of the new versions of Lazarus or FPC, a bug was fixed or the restriction was removed that the name of the component should not match the name of the unit.
For example file.
MyControl.pas

Code: Pascal  [Select][+][-]
  1. unit MyControl;
  2. type
  3.  TMyControl = class(TCustomControl)
  4.  end;
  5.  
  6.   RegisterComponents('My Controls', [TMyControl]);
  7.  
  8. end;
  9.  

In Lazarus 2.X it gave a compilation error.
I don't remember the error text.
I had to rename the file to MyControls.pas

In Lazarus 3.2, the MyControl.pas file with the TMyControl component does not generate compilation errors.
Is this a new feature or bug in Lazarus?
Can I now rely on the fact that I can name the file with the TMyControl component - MyControl.pas?
Is there a description of this new FPC feature?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5690
  • Compiler Developer
Re: Compilation error when the TComponentName matches the unit name.
« Reply #1 on: August 11, 2024, 08:53:00 pm »
Maybe you confuse that with a form file where you'll have a global variable with the name of the form minus the T in the same unit and thus you can't use the same name. In your example I see no error regarding this (I am missing a interface, implementation and initialization however ;) )

 

TinyPortal © 2005-2018